Skip to content

Commit

Permalink
Updated BakedVC shader to use baked sunlight map
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmonik committed Nov 14, 2023
1 parent 1945793 commit 9afe991
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions OVP/D3D9Client/D3D9Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions OVP/D3D9Client/D3D9Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class D3D9Effect {
static D3DXHANDLE eIrradMap;
static D3DXHANDLE eAmbientMap;
static D3DXHANDLE eCombinedMap;
static D3DXHANDLE eCombSunMap;

// Legacy Atmosphere -----------------------------------------------
static D3DXHANDLE eGlobalAmb;
Expand Down
2 changes: 2 additions & 0 deletions OVP/D3D9Client/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions OVP/D3D9Client/shaders/BakedVC.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions OVP/D3D9Client/shaders/D3D9Client.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------

Expand Down Expand Up @@ -312,6 +313,18 @@ sampler BakedLightS = sampler_state // Primary Mesh texture sampler
AddressV = WRAP;
};

sampler BakedSunS = sampler_state // Primary Mesh texture sampler
{
Texture = <gCombinedSunMap>;
MinFilter = ANISOTROPIC;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = ANISOTROPY_MACRO;
MipMapLODBias = 0;
AddressU = WRAP;
AddressV = WRAP;
};

sampler BakedAOS = sampler_state // Primary Mesh texture sampler
{
Texture = <gAmbientMap>;
Expand Down

0 comments on commit 9afe991

Please sign in to comment.