diff --git a/include_files/depthpass.lua b/include_files/depthpass.lua index 507a62f..72da0ad 100644 --- a/include_files/depthpass.lua +++ b/include_files/depthpass.lua @@ -47,10 +47,13 @@ local depthRT = render.GetResolvedFullFrameDepth() local hRender = dummyFn local BeginDepthPass = shaderlib.BeginDepthPass local EndDepthPass = shaderlib.EndDepthPass +local RenderView = render.RenderView +local rClearDepth = render.ClearDepth local function PreDrawEffectsHK() if bDepthPass then return end bDepthPass = true + halo.Render = dummyFn MaterialOverride( depthWriteMat ) @@ -66,9 +69,9 @@ local function PreDrawEffectsHK() PopRenderTarget() rClear(0,0,0,0) - render.RenderView() - EndDepthPass() + RenderView() + EndDepthPass() MaterialOverride() BrushMaterialOverride() @@ -79,14 +82,28 @@ local function PreDrawEffectsHK() bDepthPass = false end -local rClearDepth = render.ClearDepth - - +local zero_vec = Vector(0,0,0) +local min,max = zero_vec, zero_vec function shaderlib.__INIT() halo = halo hRender = halo.Render - hook.Add("PreDrawViewModel", "!!!EGSM_ImTooLazy", function() if bDepthPass then rClearDepth() end end) - hook.Add( "RenderScene", "!!!EGSM_ImTooLazy", PreDrawEffectsHK) + hook.Add("PreDrawViewModel", "!!!EGSM_ImTooLazy", function() if bDepthPass then rClearDepth() end end) + hook.Add("NeedsDepthPass", "!!!EGSM_ImTooLazy", PreDrawEffectsHK) + + hook.Add("PostDraw2DSkyBox", "!!!EGSM_ImTooLazy", function() + local rt = render.GetRenderTarget() + if !rt or rt:GetName() != "egsm_skyboxrt" + then + return + end + cam.Start3D( zero_vec, EyeAngles() ) + min,max = game.GetWorld():GetModelBounds() + + render.SetMaterial( depthWriteMat ) + + render.DrawBox( zero_vec, angle_zero, max, min, color_white ) + cam.End3D() + end) end diff --git a/source/depthpass.lua.inc b/source/depthpass.lua.inc index 3d56464..fa57d86 100644 --- a/source/depthpass.lua.inc +++ b/source/depthpass.lua.inc @@ -1 +1 @@ -const char depthpass_lua[] = "\n""local depthWriteMat = CreateMaterial( \"egsm/depthmat\", \"DepthWrite\", {\n""\n"" [\"$no_fullbright\"] = \"1\",\n""\n"" [\"$color_depth\"] = \"1\",\n""\n"" [\"$alpha_test\"] = \"0\",\n""\n""} )\n""\n""\n""local bDepthPass = false\n""\n""local halo = {}\n""\n""local render = render\n""\n""\n""MaterialOverride = MaterialOverride or render.MaterialOverride\n""\n""BrushMaterialOverride = BrushMaterialOverride or render.BrushMaterialOverride \n""\n""WorldMaterialOverride = WorldMaterialOverride or render.WorldMaterialOverride \n""\n""ModelMaterialOverride = ModelMaterialOverride or render.ModelMaterialOverride \n""\n""\n""local MaterialOverride = MaterialOverride\n""\n""local BrushMaterialOverride = BrushMaterialOverride\n""\n""local WorldMaterialOverride = WorldMaterialOverride\n""\n""local ModelMaterialOverride = ModelMaterialOverride\n""\n""\n""function render.MaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" MaterialOverride(m)\n""\n""end\n""\n""\n""function render.BrushMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" BrushMaterialOverride(m)\n""\n""end\n""\n""\n""function render.WorldMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" WorldMaterialOverride(m)\n""\n""end\n""\n""function render.ModelMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" ModelMaterialOverride(m)\n""\n""end\n""\n""\n""local function dummyFn() end\n""\n""\n""local PushRenderTarget = render.PushRenderTarget\n""\n""local PopRenderTarget = render.PopRenderTarget\n""\n""local rClear = render.Clear\n""\n""local depthRT = render.GetResolvedFullFrameDepth()\n""\n""local hRender = dummyFn\n""\n""local BeginDepthPass = shaderlib.BeginDepthPass\n""\n""local EndDepthPass = shaderlib.EndDepthPass\n""\n""\n""local function PreDrawEffectsHK() \n""\n"" if bDepthPass then return end\n""\n"" bDepthPass = true\n""\n"" halo.Render = dummyFn\n""\n"" \n""\n"" MaterialOverride( depthWriteMat )\n""\n"" BrushMaterialOverride( depthWriteMat )\n""\n"" WorldMaterialOverride( depthWriteMat )\n""\n"" ModelMaterialOverride( depthWriteMat )\n""\n"" \n""\n"" BeginDepthPass()\n""\n"" rClear(0,0,0,0) \n""\n"" PopRenderTarget()\n""\n"" \n""\n"" rClear(0,0,0,0)\n""\n"" PopRenderTarget()\n""\n"" \n""\n"" rClear(0,0,0,0) \n""\n"" render.RenderView()\n""\n"" EndDepthPass()\n""\n""\n""\n"" MaterialOverride()\n""\n"" BrushMaterialOverride()\n""\n"" WorldMaterialOverride()\n""\n"" ModelMaterialOverride()\n""\n"" \n""\n"" halo.Render = hRender\n""\n"" bDepthPass = false\n""\n""end\n""\n""\n""local rClearDepth = render.ClearDepth\n""\n""\n""\n""\n""function shaderlib.__INIT()\n""\n"" halo = halo\n""\n"" hRender = halo.Render\n""\n""\n"" hook.Add(\"PreDrawViewModel\", \"!!!EGSM_ImTooLazy\", function() if bDepthPass then rClearDepth() end end)\n""\n"" hook.Add( \"RenderScene\", \"!!!EGSM_ImTooLazy\", PreDrawEffectsHK)\n""\n""end\n""\n""\n"; \ No newline at end of file +const char depthpass_lua[] = "\n""local depthWriteMat = CreateMaterial( \"egsm/depthmat\", \"DepthWrite\", {\n""\n"" [\"$no_fullbright\"] = \"1\",\n""\n"" [\"$color_depth\"] = \"1\",\n""\n"" [\"$alpha_test\"] = \"0\",\n""\n""} )\n""\n""\n""local bDepthPass = false\n""\n""local halo = {}\n""\n""local render = render\n""\n""\n""MaterialOverride = MaterialOverride or render.MaterialOverride\n""\n""BrushMaterialOverride = BrushMaterialOverride or render.BrushMaterialOverride \n""\n""WorldMaterialOverride = WorldMaterialOverride or render.WorldMaterialOverride \n""\n""ModelMaterialOverride = ModelMaterialOverride or render.ModelMaterialOverride \n""\n""\n""local MaterialOverride = MaterialOverride\n""\n""local BrushMaterialOverride = BrushMaterialOverride\n""\n""local WorldMaterialOverride = WorldMaterialOverride\n""\n""local ModelMaterialOverride = ModelMaterialOverride\n""\n""\n""function render.MaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" MaterialOverride(m)\n""\n""end\n""\n""\n""function render.BrushMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" BrushMaterialOverride(m)\n""\n""end\n""\n""\n""function render.WorldMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" WorldMaterialOverride(m)\n""\n""end\n""\n""function render.ModelMaterialOverride(m)\n""\n"" if bDepthPass then return end\n""\n"" ModelMaterialOverride(m)\n""\n""end\n""\n""\n""local function dummyFn() end\n""\n""\n""local PushRenderTarget = render.PushRenderTarget\n""\n""local PopRenderTarget = render.PopRenderTarget\n""\n""local rClear = render.Clear\n""\n""local depthRT = render.GetResolvedFullFrameDepth()\n""\n""local hRender = dummyFn\n""\n""local BeginDepthPass = shaderlib.BeginDepthPass\n""\n""local EndDepthPass = shaderlib.EndDepthPass\n""\n""local RenderView = render.RenderView\n""\n""local rClearDepth = render.ClearDepth\n""\n""\n""local function PreDrawEffectsHK() \n""\n"" if bDepthPass then return end\n""\n"" bDepthPass = true\n""\n"" \n""\n"" halo.Render = dummyFn\n""\n"" \n""\n"" MaterialOverride( depthWriteMat )\n""\n"" BrushMaterialOverride( depthWriteMat )\n""\n"" WorldMaterialOverride( depthWriteMat )\n""\n"" ModelMaterialOverride( depthWriteMat )\n""\n"" \n""\n"" BeginDepthPass()\n""\n"" rClear(0,0,0,0) \n""\n"" PopRenderTarget()\n""\n"" \n""\n"" rClear(0,0,0,0)\n""\n"" PopRenderTarget()\n""\n"" \n""\n"" rClear(0,0,0,0) \n""\n""\n"" RenderView()\n""\n"" EndDepthPass()\n""\n""\n"" MaterialOverride()\n""\n"" BrushMaterialOverride()\n""\n"" WorldMaterialOverride()\n""\n"" ModelMaterialOverride()\n""\n"" \n""\n"" halo.Render = hRender\n""\n"" bDepthPass = false\n""\n""end\n""\n""\n""local zero_vec = Vector(0,0,0)\n""\n""local min,max = zero_vec, zero_vec\n""\n""\n""function shaderlib.__INIT()\n""\n"" halo = halo\n""\n"" hRender = halo.Render\n""\n""\n"" hook.Add(\"PreDrawViewModel\", \"!!!EGSM_ImTooLazy\", function() if bDepthPass then rClearDepth() end end) \n""\n"" hook.Add(\"NeedsDepthPass\", \"!!!EGSM_ImTooLazy\", PreDrawEffectsHK)\n""\n"" \n""\n"" hook.Add(\"PostDraw2DSkyBox\", \"!!!EGSM_ImTooLazy\", function()\n""\n"" local rt = render.GetRenderTarget()\n""\n"" if !rt or rt:GetName() != \"egsm_skyboxrt\" \n""\n"" then \n""\n"" return\n""\n"" end\n""\n"" cam.Start3D( zero_vec, EyeAngles() )\n""\n"" min,max = game.GetWorld():GetModelBounds()\n""\n"" \n""\n"" render.SetMaterial( depthWriteMat )\n""\n"" \n""\n"" render.DrawBox( zero_vec, angle_zero, max, min, color_white )\n""\n"" cam.End3D()\n""\n"" end) \n""\n""end\n""\n""\n"; \ No newline at end of file diff --git a/source/shaderlib.cpp b/source/shaderlib.cpp index 96e730c..c317f37 100644 --- a/source/shaderlib.cpp +++ b/source/shaderlib.cpp @@ -1141,6 +1141,26 @@ namespace ShaderLib CClientShadowMgr_ComputeShadowDepthTextures_trampoline()(_this, viewSetup); } + + struct WaterRenderInfo_t + { + bool m_bCheapWater : 1; + bool m_bReflect : 1; + bool m_bRefract : 1; + bool m_bReflectEntities : 1; + bool m_bDrawWaterSurface : 1; + bool m_bOpaqueWater : 1; + + }; + + Define_method_Hook(void, CViewRender_DetermineWaterRenderInfo, void*, const void* idc, WaterRenderInfo_t &info) + { + CViewRender_DetermineWaterRenderInfo_trampoline()(_this, idc, info); + if (bDepthPass) + { + info.m_bCheapWater = false; + } + } Define_method_Hook(void, CBaseWorldView_SSAO_DepthPass, void*) { @@ -1202,9 +1222,9 @@ namespace ShaderLib int MenuInit(GarrysMod::Lua::ILuaBase* LUA) { - static Color msgc(100, 255, 100, 255); + static Color msgc(100, 255, 100, 255); ConColorMsg(msgc, "ShaderLib\n"); - + if (!Sys_LoadInterface("materialsystem", "MaterialSystemHardwareConfig012", NULL, (void**)&g_pHardwareConfig)) { ShaderLibError("MaterialSystemHardwareConfig012 == NULL"); } if (g_pHardwareConfig->GetDXSupportLevel() < 90) { ShaderLibError("Unsupported DirectX version(dxlevel<90)"); }; if (!Sys_LoadInterface("materialsystem", "ShaderSystem002", NULL, (void**)&g_pSLShaderSystem)) { ShaderLibError("IShaderSystem == NULL"); } @@ -1314,6 +1334,18 @@ namespace ShaderLib if (!CClientShadowMgr_ComputeShadowDepthTextures) { ShaderLibError("CClientShadowMgr::ComputeShadowDepthTextures == NULL\n"); return 0; } Setup_Hook(CClientShadowMgr_ComputeShadowDepthTextures, CClientShadowMgr_ComputeShadowDepthTextures); } + + + { + static const char sign[] = + HOOK_SIGN_CHROMIUM_x32("55 8B EC 83 EC 10 56 57 8B 7D 0C 89 4D F0 8A 07 24 E1 0C 21 88 07 8B 45 08 83 38 FF 8B 70 14 0F 84 ? ? ? ? 85 F6 0F 84 ? ? ? ? A1 ? ? ? ? B9 ? ? ? ? FF 50 34 8A 0F F7 D8 1A C0 80 E1 EF 24 10 0A C8 88 0F F6") + HOOK_SIGN_M("55 8B EC 83 EC 0C 8B 45 08 56 8B 75 0C 57 89 4D F4 8A 16 80 E2 E1 80 CA 21 88 16 83 38 FF 8B 78 14 0F 84 ? ? ? ? 85 FF 0F 84 ? ? ? ? 8B ? ? ? ? ? 8B 41 48 53 8D 59 48 85 C0 74 19 80 38 00 74 14 8B CB E8 ? ? ? ? 50 E8") + HOOK_SIGN_x64("48 89 4C 24 08 56 41 55 41 56 48 83 EC 60 41 0F B6 00 49 8B F0 24 E1 4C 8B EA 0C 21 41 88 00 83 3A FF 4C 8B 72 18 0F 84 ? ? ? ? 4D 85 F6 0F 84 ? ? ? ? 48 8B ? ? ? ? ? 48 8D ? ? ? ? ? FF 50 68 F7 D8 0F B6 06 1A C9 24") + + void* CViewRender_DetermineWaterRenderInfo = ScanSign(clientdll, sign, sizeof(sign) - 1); + if (!CViewRender_DetermineWaterRenderInfo) { ShaderLibError("CViewRender::DetermineWaterRenderInfo == NULL\n"); return 0; } + Setup_Hook(CViewRender_DetermineWaterRenderInfo, CViewRender_DetermineWaterRenderInfo); + } { static const char sign[] = diff --git a/source/shaderlib.h b/source/shaderlib.h index 9950f8d..856ab35 100644 --- a/source/shaderlib.h +++ b/source/shaderlib.h @@ -20,7 +20,7 @@ #include #include -extern IMaterialSystemHardwareConfig* g_pHardwareConfig; +extern IMaterialSystemHardwareConfig* g_pHardwareConfig; namespace ShaderLib { @@ -251,7 +251,9 @@ namespace ShaderLib if (bind->Type == bind->Texture) { - LoadTexture(bind->ParamIndex); + int envMapFlags = g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0; + envMapFlags |= TEXTUREFLAGS_ALL_MIPS; + LoadTexture(bind->ParamIndex, envMapFlags); } else if (bind->Type == bind->Cubemap) { diff --git a/source/version.h b/source/version.h index 9a98040..f10e851 100644 --- a/source/version.h +++ b/source/version.h @@ -1 +1 @@ -#define EGSM_VERSION 10 \ No newline at end of file +#define EGSM_VERSION 11 \ No newline at end of file