From 9afe991cbc6cb2bff0c77fc25767dddfb81231f6 Mon Sep 17 00:00:00 2001 From: jarmonik Date: Tue, 14 Nov 2023 21:59:59 +0200 Subject: [PATCH] Updated BakedVC shader to use baked sunlight map --- OVP/D3D9Client/D3D9Effect.cpp | 2 ++ OVP/D3D9Client/D3D9Effect.h | 1 + OVP/D3D9Client/Mesh.cpp | 2 ++ OVP/D3D9Client/shaders/BakedVC.fx | 8 ++++++-- OVP/D3D9Client/shaders/D3D9Client.fx | 13 +++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/OVP/D3D9Client/D3D9Effect.cpp b/OVP/D3D9Client/D3D9Effect.cpp index b39a78ef6..62c299bf7 100644 --- a/OVP/D3D9Client/D3D9Effect.cpp +++ b/OVP/D3D9Client/D3D9Effect.cpp @@ -83,6 +83,7 @@ D3DXHANDLE D3D9Effect::eTransmMap = 0; D3DXHANDLE D3D9Effect::eIrradMap = 0; D3DXHANDLE D3D9Effect::eAmbientMap = 0; D3DXHANDLE D3D9Effect::eCombinedMap = 0; +D3DXHANDLE D3D9Effect::eCombSunMap = 0; D3DXHANDLE D3D9Effect::eSpecularMode = 0; D3DXHANDLE D3D9Effect::eHazeMode = 0; @@ -486,6 +487,7 @@ void D3D9Effect::D3D9TechInit(D3D9Client *_gc, LPDIRECT3DDEVICE9 _pDev, const ch eIrradMap = FX->GetParameterByName(0,"gIrradianceMap"); eAmbientMap = FX->GetParameterByName(0, "gAmbientMap"); eCombinedMap = FX->GetParameterByName(0, "gCombinedMap"); + eCombSunMap = FX->GetParameterByName(0, "gCombinedSunMap"); // Atmosphere ----------------------------------------------------------- eGlobalAmb = FX->GetParameterByName(0,"gGlobalAmb"); diff --git a/OVP/D3D9Client/D3D9Effect.h b/OVP/D3D9Client/D3D9Effect.h index a1086c278..e320ebcc5 100644 --- a/OVP/D3D9Client/D3D9Effect.h +++ b/OVP/D3D9Client/D3D9Effect.h @@ -185,6 +185,7 @@ class D3D9Effect { static D3DXHANDLE eIrradMap; static D3DXHANDLE eAmbientMap; static D3DXHANDLE eCombinedMap; + static D3DXHANDLE eCombSunMap; // Legacy Atmosphere ----------------------------------------------- static D3DXHANDLE eGlobalAmb; diff --git a/OVP/D3D9Client/Mesh.cpp b/OVP/D3D9Client/Mesh.cpp index 57fb9470c..d6f501cb8 100644 --- a/OVP/D3D9Client/Mesh.cpp +++ b/OVP/D3D9Client/Mesh.cpp @@ -2030,9 +2030,11 @@ void D3D9Mesh::Render(const LPD3DXMATRIX pW, int iTech, LPDIRECT3DCUBETEXTURE9 * LPDIRECT3DTEXTURE9 pAmbi = Tex[ti]->GetMap(MAP_AMBIENT); LPDIRECT3DTEXTURE9 pComb = (bm == BakedLights.end() ? NULL : bm->second.pCombined); + LPDIRECT3DTEXTURE9 pSun = (bm == BakedLights.end() ? NULL : bm->second.pSunAOComb); if (pAmbi) FX->SetTexture(eAmbientMap, pAmbi); if (pComb) FX->SetTexture(eCombinedMap, pComb); + if (pSun) FX->SetTexture(eCombSunMap, pSun); FC.Baked = (pComb != NULL); FC.BakedAO = (pAmbi != NULL); diff --git a/OVP/D3D9Client/shaders/BakedVC.fx b/OVP/D3D9Client/shaders/BakedVC.fx index 7ae77e672..1bca1a88e 100644 --- a/OVP/D3D9Client/shaders/BakedVC.fx +++ b/OVP/D3D9Client/shaders/BakedVC.fx @@ -46,9 +46,13 @@ float4 BakedVC_PS(float4 sc : VPOS, PBRData frg) : COLOR else cEmis = 0; float3 cBL = 0; + float3 cBS = 0; float3 cBAO = 0; - if (gCfg.Baked) cBL = tex2D(BakedLightS, frg.tex0.xy).rgb; + if (gCfg.Baked) { + cBL = tex2D(BakedLightS, frg.tex0.xy).rgb; + cBS = tex2D(BakedSunS, frg.tex0.xy).rgb; + } if (gCfg.BakedAO) cBAO = tex2D(BakedAOS, frg.tex0.xy).rgb; @@ -186,7 +190,7 @@ float4 BakedVC_PS(float4 sc : VPOS, PBRData frg) : COLOR fA += fRgh * fMetal * 0.05f; // gVCAmbient is an application and debug controls controllable variable - float3 zD = cDiff.rgb * fA * LightFXSq(gMtrl.diffuse.rgb * (Sq(cSun * fR * dLN)) + Sq(gMtrl.emissive.rgb) + Sq(cBL) + Sq(gVCAmbient)); + float3 zD = cDiff.rgb * fA * LightFXSq(gMtrl.diffuse.rgb * (Sq(cSun * fR * dLN)) + Sq(gMtrl.emissive.rgb) + Sq(cBL) + Sq(cBS) + Sq(gVCAmbient)); // Combine specular terms float3 zS = cS * (cSun * dLN); diff --git a/OVP/D3D9Client/shaders/D3D9Client.fx b/OVP/D3D9Client/shaders/D3D9Client.fx index bc01733bb..d362685f4 100644 --- a/OVP/D3D9Client/shaders/D3D9Client.fx +++ b/OVP/D3D9Client/shaders/D3D9Client.fx @@ -156,6 +156,7 @@ uniform extern texture gTransmMap; // Transmittance Map uniform extern texture gIrradianceMap; // Irradiance Map uniform extern texture gAmbientMap; // Baked Ambient occlusion map uniform extern texture gCombinedMap; // Combined baked light map +uniform extern texture gCombinedSunMap; // Combined baked light map // Legacy Atmosphere -------------------------------------------------------- @@ -312,6 +313,18 @@ sampler BakedLightS = sampler_state // Primary Mesh texture sampler AddressV = WRAP; }; +sampler BakedSunS = sampler_state // Primary Mesh texture sampler +{ + Texture = ; + MinFilter = ANISOTROPIC; + MagFilter = LINEAR; + MipFilter = LINEAR; + MaxAnisotropy = ANISOTROPY_MACRO; + MipMapLODBias = 0; + AddressU = WRAP; + AddressV = WRAP; +}; + sampler BakedAOS = sampler_state // Primary Mesh texture sampler { Texture = ;