Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added features/TruePBR/CORE
Empty file.
2 changes: 2 additions & 0 deletions features/TruePBR/Shaders/Features/TruePBR.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Info]
Version = 1-0-0
5 changes: 0 additions & 5 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "ShaderCache.h"
#include "State.h"
#include "TruePBR.h"
#include "Utils/D3D.h"

#include "Features/DynamicCubemaps.h"
Expand Down Expand Up @@ -217,7 +216,6 @@ void Deferred::PrepassPasses()
auto context = globals::d3d::context;
context->OMSetRenderTargets(0, nullptr, nullptr); // Unbind all bound render targets

globals::truePBR->PrePass();
Feature::ForEachLoadedFeature("Prepass", [](Feature* feature) { feature->Prepass(); }, true);
}

Expand Down Expand Up @@ -768,7 +766,4 @@ void Deferred::Hooks::Renderer_ResetState::thunk(void* This)
ID3D11Buffer* buffers[3] = { state->permutationCB->CB(), state->sharedDataCB->CB(), state->featureDataCB->CB() };
context->PSSetConstantBuffers(4, 3, buffers);
context->CSSetConstantBuffers(5, 2, buffers + 1);

auto* singleton = globals::truePBR;
singleton->SetupFrame();
}
2 changes: 2 additions & 0 deletions src/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "WeatherVariableRegistry.h"

#include "State.h"
#include "TruePBR.h"

void Feature::Load(json& o_json)
{
Expand Down Expand Up @@ -209,6 +210,7 @@ void Feature::WriteDiskCacheInfo(CSimpleIniA& a_ini)
const std::vector<Feature*>& Feature::GetFeatureList()
{
static std::vector<Feature*> features = {
&globals::features::truePBR,
&globals::features::volumetricShadows,
&globals::features::grassLighting,
&globals::features::grassCollision,
Expand Down
12 changes: 12 additions & 0 deletions src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ struct Feature
virtual void Prepass() {}
virtual void EarlyPrepass() {}

/**
* @brief Called during disk-cache shader loading to generate additional shader permutations.
*
* Invoked once per BSShader load when the shader cache is in disk-cache mode.
* Features can override this to inject custom permutation descriptors into the
* shader cache so that feature-specific technique variants are compiled and stored.
* This is a cold path (disk I/O, not per-frame); performance is not critical here.
*
* @param shader The BSShader being loaded.
*/
virtual void GenerateShaderPermutations(RE::BSShader*) {}

virtual void Load() {} // Called during SKSE Load - earliest hook point only for critical hooks like d3d
virtual void DataLoaded() {}
virtual void PostPostLoad() {}
Expand Down
2 changes: 0 additions & 2 deletions src/FeatureBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "Features/TerrainVariation.h"
#include "Features/WetnessEffects.h"

#include "TruePBR.h"

template <class... Ts>
std::pair<unsigned char*, size_t> _GetFeatureBufferData(Ts... feat_datas)
{
Expand Down
43 changes: 43 additions & 0 deletions src/Features/TerrainHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "TerrainHelper.h"

#include "Globals.h"
#include "ShaderCache.h"
#include "State.h"

Expand Down Expand Up @@ -191,4 +192,46 @@ void TerrainHelper::BSLightingShader_SetupMaterial(RE::BSLightingShaderMaterialB
state->permutationData.ExtraFeatureDescriptor &= ~(1 << textureI);
}
}
}

struct TH_TESObjectLAND_SetupMaterial
{
static bool thunk(RE::TESObjectLAND* land)
{
bool result = func(land);

// TruePBR sets flag 8 on land cells it processes as PBR; skip TerrainHelper for those.
if (!land->data.flags.any(static_cast<RE::OBJ_LAND::Flag>(8))) {
auto& terrainHelper = globals::features::terrainHelper;
if (result && terrainHelper.loaded) {
terrainHelper.TESObjectLAND_SetupMaterial(land);
}
}

return result;
}
static inline REL::Relocation<decltype(thunk)> func;
};

struct TH_BSLightingShader_SetupMaterial
{
static void thunk(RE::BSLightingShader* shader, RE::BSLightingShaderMaterialBase const* material)
{
func(shader, material);

auto& terrainHelper = globals::features::terrainHelper;
if (terrainHelper.loaded) {
terrainHelper.BSLightingShader_SetupMaterial(material);
}
}
static inline REL::Relocation<decltype(thunk)> func;
};

void TerrainHelper::PostPostLoad()
{
logger::info("[Terrain Helper] Hooking TESObjectLAND");
stl::detour_thunk<TH_TESObjectLAND_SetupMaterial>(REL::RelocationID(18368, 18791));

logger::info("[Terrain Helper] Hooking BSLightingShader::SetupMaterial");
stl::write_vfunc<0x4, TH_BSLightingShader_SetupMaterial>(RE::VTABLE_BSLightingShader[0]);
}
1 change: 1 addition & 0 deletions src/Features/TerrainHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct TerrainHelper : Feature
bool enabled = false;

virtual void DataLoaded() override;
virtual void PostPostLoad() override;
virtual bool SupportsVR() override { return true; };
virtual std::string GetFeatureModLink() override { return MakeNexusModURL(MOD_ID); }

Expand Down
3 changes: 1 addition & 2 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace globals
RenderDoc renderDoc{};
WeatherEditor weatherEditor{};
ExponentialHeightFog exponentialHeightFog{};
TruePBR truePBR{};

namespace llf
{
Expand Down Expand Up @@ -144,7 +145,6 @@ namespace globals

State* state = nullptr;
Deferred* deferred = nullptr;
TruePBR* truePBR = nullptr;
Menu* menu = nullptr;
SIE::ShaderCache* shaderCache = nullptr;

Expand All @@ -154,7 +154,6 @@ namespace globals
state = State::GetSingleton();
menu = Menu::GetSingleton();
deferred = Deferred::GetSingleton();
truePBR = TruePBR::GetSingleton();
}

void ReInit()
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace globals
extern RenderDoc renderDoc;
extern WeatherEditor weatherEditor;
extern ExponentialHeightFog exponentialHeightFog;
extern TruePBR truePBR;

namespace llf
{
Expand Down Expand Up @@ -257,7 +258,6 @@ namespace globals

extern State* state;
extern Deferred* deferred;
extern TruePBR* truePBR;
extern Menu* menu;
extern SIE::ShaderCache* shaderCache;

Expand Down
61 changes: 3 additions & 58 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
#include "Menu.h"
#include "ShaderCache.h"
#include "State.h"
#include "TruePBR.h"
#include "Util.h"

#include "Features/HDRDisplay.h"
#include "Features/InteriorSun.h"
#include "Features/LightLimitFix.h"
#include "Features/TerrainHelper.h"
#include "Features/Upscaling.h"
#include "Features/VR.h"
#include "Features/VolumetricLighting.h"
Expand Down Expand Up @@ -77,11 +75,11 @@ struct BSShader_LoadShaders

auto state = globals::state;
auto shaderCache = globals::shaderCache;
auto truePBR = globals::truePBR;

if (shaderCache->IsDiskCache() || shaderCache->IsDump()) {
if (shaderCache->IsDiskCache()) {
truePBR->GenerateShaderPermutations(shader);
Feature::ForEachLoadedFeature("GenerateShaderPermutations", [shader](Feature* feature) {
feature->GenerateShaderPermutations(shader);
});
}

for (const auto& entry : shader->vertexShaders) {
Expand Down Expand Up @@ -758,53 +756,6 @@ namespace Hooks
static inline REL::Relocation<decltype(thunk)> func;
};

struct TESObjectLAND_SetupMaterial
{
static bool thunk(RE::TESObjectLAND* land)
{
bool vanillaResult = func(land);

// setup material for PBR
auto TruePBRSingleton = globals::truePBR;
if (TruePBRSingleton->TESObjectLAND_SetupMaterial(land)) {
// if PBR, we are done
return true;
}

// setup material for terrain helper
auto& terrainHelper = globals::features::terrainHelper;
if (vanillaResult && terrainHelper.loaded) {
terrainHelper.TESObjectLAND_SetupMaterial(land);
}

return vanillaResult;
}
static inline REL::Relocation<decltype(thunk)> func;
};

struct BSLightingShader_SetupMaterial
{
static void thunk(RE::BSLightingShader* shader, RE::BSLightingShaderMaterialBase const* material)
{
// setup material for PBR
auto TruePBRSingleton = globals::truePBR;
if (TruePBRSingleton->BSLightingShader_SetupMaterial(shader, material)) {
// if PBR, we are done
return;
}

// vanilla
func(shader, material);

// terrain helper
auto& terrainHelper = globals::features::terrainHelper;
if (terrainHelper.loaded) {
terrainHelper.BSLightingShader_SetupMaterial(material);
}
};
static inline REL::Relocation<decltype(thunk)> func;
};

#ifdef TRACY_ENABLE
struct Main_Update
{
Expand Down Expand Up @@ -1010,12 +961,6 @@ namespace Hooks
stl::write_thunk_call<GrassExtensions::BSGrassShaderProperty_ctor>(REL::RelocationID(15214, 15383).address() + REL::Relocate(0x45B, 0x4F5));
stl::write_vfunc<0x6, GrassExtensions::BSGrassShader_SetupGeometry>(RE::VTABLE_BSGrassShader[0]);

logger::info("Hooking TESObjectLAND");
stl::detour_thunk<TESObjectLAND_SetupMaterial>(REL::RelocationID(18368, 18791));

logger::info("Hooking BSLightingShader");
stl::write_vfunc<0x4, BSLightingShader_SetupMaterial>(RE::VTABLE_BSLightingShader[0]);

// Patch render space in BSLightingShader::SetupGeometry to always use world space
// The variable updateEyePosition is set to 1 when not skinned. By patching to be 0 it will always use world space
// We offset from the base address of the containing function to the start of the patch
Expand Down
24 changes: 0 additions & 24 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "Menu/ThemeManager.h"
#include "ShaderCache.h"
#include "State.h"
#include "TruePBR.h"
#include "Util.h"
#include "Utils/UI.h"

Expand Down Expand Up @@ -771,9 +770,7 @@ void Menu::DrawGeneralSettings()
*/
void Menu::DrawAdvancedSettings()
{
// Render advanced settings using extracted component
AdvancedSettingsRenderer::RenderAdvancedSettings(
[this]() { globals::truePBR->DrawSettings(); },
[this]() { DrawDisableAtBootSettings(); });
}

Expand All @@ -789,27 +786,6 @@ void Menu::DrawDisableAtBootSettings()

ImGui::Spacing();

if (ImGui::CollapsingHeader("Special Features", ImGuiTreeNodeFlags_DefaultOpen)) {
// Prepare a sorted list of special feature names
std::vector<std::string> specialFeatureNames;
for (const auto& [featureName, _] : state->specialFeatures) {
specialFeatureNames.push_back(featureName);
}
std::sort(specialFeatureNames.begin(), specialFeatureNames.end());

// Display sorted special features
for (const auto& featureName : specialFeatureNames) {
// Check if the feature is currently disabled
bool isDisabled = disabledFeatures.contains(featureName) && disabledFeatures[featureName];

// Create a checkbox for each feature
if (ImGui::Checkbox(featureName.c_str(), &isDisabled)) {
// Update the disabledFeatures map based on user interaction
disabledFeatures[featureName] = isDisabled;
}
}
}

if (ImGui::CollapsingHeader("Features", ImGuiTreeNodeFlags_DefaultOpen)) {
// Prepare a sorted list of feature pointers
auto featureList = Feature::GetFeatureList();
Expand Down
15 changes: 0 additions & 15 deletions src/Menu/AdvancedSettingsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
#include "Menu.h"
#include "ShaderCache.h"
#include "State.h"
#include "TruePBR.h"
#include "Util.h"
#include "Utils/Format.h"
#include "Utils/UI.h"

void AdvancedSettingsRenderer::RenderAdvancedSettings(
const std::function<void()>& drawTruePBRSettings,
const std::function<void()>& drawDisableAtBootSettings)
{
// Use TabBar system - tabs sorted alphabetically
Expand Down Expand Up @@ -51,14 +49,6 @@ void AdvancedSettingsRenderer::RenderAdvancedSettings(
ImGui::EndTabItem();
}

// PBR Settings Tab
if (MenuFonts::BeginTabItemWithFont("PBR Settings", Menu::FontRole::Subheading)) {
if (ImGui::BeginChild("##PBRSettingsContent", ImVec2(0, 0), false)) {
RenderPBRSection(drawTruePBRSettings);
}
ImGui::EndChild();
ImGui::EndTabItem();
}
// Shader Debug Tab
if (MenuFonts::BeginTabItemWithFont("Shader Debug", Menu::FontRole::Subheading)) {
if (ImGui::BeginChild("##ShaderDebugContent", ImVec2(0, 0), false)) {
Expand Down Expand Up @@ -514,11 +504,6 @@ void AdvancedSettingsRenderer::RenderShaderDebugSection()
}
}

void AdvancedSettingsRenderer::RenderPBRSection(const std::function<void()>& drawTruePBRSettings)
{
drawTruePBRSettings();
}

void AdvancedSettingsRenderer::RenderDisableAtBootSection(const std::function<void()>& drawDisableAtBootSettings)
{
drawDisableAtBootSettings();
Expand Down
2 changes: 0 additions & 2 deletions src/Menu/AdvancedSettingsRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ class AdvancedSettingsRenderer
{
public:
static void RenderAdvancedSettings(
const std::function<void()>& drawTruePBRSettings,
const std::function<void()>& drawDisableAtBootSettings);

private:
static void RenderLoggingSection();
static void RenderShaderDebugSection();
static void RenderPBRSection(const std::function<void()>& drawTruePBRSettings);
static void RenderDisableAtBootSection(const std::function<void()>& drawDisableAtBootSettings);
static void RenderDeveloperSection();
static void RenderTestingSection();
Expand Down
Loading
Loading