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
16 changes: 2 additions & 14 deletions features/Grass Lighting/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ VS_OUTPUT main(VS_INPUT input)

# if !defined(VR)
uint eyeIndex = 0;
uint eyeIndexX3 = 0;
uint eyeIndexX4 = 0;
# else
/*
https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/htmlpresent
Expand All @@ -194,12 +192,8 @@ VS_OUTPUT main(VS_INPUT input)
clipPositionOut = clipPos
*/
float4 r0, r1, r2, r3, r4, r5, r6;
uint4 bitmask, uiDest;
float4 fDest;

uint eyeIndex = cb13[0].y * (input.InstanceID.x & 1);
uint eyeIndexX3 = eyeIndex * 3;
uint eyeIndexX4 = eyeIndex << 2;
# endif // VR

float3x3 world3x3 = float3x3(input.InstanceData2.xyz, input.InstanceData3.xyz, float3(input.InstanceData4.x, input.InstanceData2.w, input.InstanceData3.w));
Expand Down Expand Up @@ -437,20 +431,14 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if !defined(VR)
uint eyeIndex = 0;
uint eyeOffset = 0;
# else
float stereoUV = input.HPosition.x * cb0[2].xy + cb0[2].zw;
stereoUV = stereoUV * DynamicResolutionParams2.x;

uint eyeIndex = (stereoUV >= 0.5) ? 1 : 0;
uint eyeOffset = eyeIndex;
uint bitmask;
bitmask = ((~(-1 << 1)) << 2) & 0xffffffff;
eyeOffset = (((uint)eyeOffset << 2) & bitmask) | ((uint)0 & ~bitmask);

# endif // !VR

psout.MotionVectors = GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeOffset);
psout.MotionVectors = GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeIndex);

float3 ddx = ddx_coarse(input.ViewSpacePosition);
float3 ddy = ddy_coarse(input.ViewSpacePosition);
Expand Down Expand Up @@ -487,7 +475,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
dirLightColor *= shadowColor.x;

# if defined(SCREEN_SPACE_SHADOWS)
float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition, eyeOffset);
float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition, eyeIndex);
dirLightColor *= dirLightSShadow;
# endif // !SCREEN_SPACE_SHADOWS

Expand Down
12 changes: 5 additions & 7 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void Menu::DrawSettings()

ImGui::Spacing();

if (ImGui::CollapsingHeader("Menu", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("Menu", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
if (settingToggleKey) {
ImGui::Text("Press any key to set as toggle key...");
} else {
Expand All @@ -361,7 +361,7 @@ void Menu::DrawSettings()
}
}

if (ImGui::CollapsingHeader("Advanced", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("Advanced", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
bool useDump = shaderCache.IsDump();
if (ImGui::Checkbox("Dump Shaders", &useDump)) {
shaderCache.SetDump(useDump);
Expand Down Expand Up @@ -397,7 +397,7 @@ void Menu::DrawSettings()
}
}

if (ImGui::CollapsingHeader("General", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("General", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
bool useCustomShaders = shaderCache.IsEnabled();
if (ImGui::BeginTable("##GeneralToggles", 3, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextColumn();
Expand Down Expand Up @@ -442,16 +442,14 @@ void Menu::DrawSettings()
}
}

if (ImGui::CollapsingHeader("Replace Original Shaders", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("Replace Original Shaders", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
auto state = State::GetSingleton();
if (ImGui::BeginTable("##ReplaceToggles", 3, ImGuiTableFlags_SizingStretchSame)) {
for (int classIndex = 0; classIndex < RE::BSShader::Type::Total - 1; ++classIndex) {
ImGui::TableNextColumn();

auto type = (RE::BSShader::Type)(classIndex + 1);
if (!(SIE::ShaderCache::IsSupportedShader(type) ||
// allow all shaders if debug or trace logging
(state->GetLogLevel()) <= spdlog::level::debug)) {
if (!(SIE::ShaderCache::IsSupportedShader(type) || state->IsDeveloperMode())) {
ImGui::BeginDisabled();
ImGui::Checkbox(std::format("{}", magic_enum::enum_name(type)).c_str(), &state->enabledClasses[classIndex]);
ImGui::EndDisabled();
Expand Down
24 changes: 12 additions & 12 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ namespace SIE
++defines;
}

if (REL::Module::IsVR()) {
defines[0] = { "VR", nullptr };
++defines;
}
VanillaGetLightingShaderDefines(descriptor, defines);
}

Expand Down Expand Up @@ -286,10 +282,6 @@ namespace SIE
++defines;
}

if (REL::Module::IsVR()) {
defines[0] = { "VR", nullptr };
++defines;
}
defines[0] = { nullptr, nullptr };
}

Expand Down Expand Up @@ -1057,8 +1049,13 @@ namespace SIE
} else if (shaderClass == ShaderClass::Pixel) {
defines[0] = { "PSHADER", nullptr };
}
defines[1] = { nullptr, nullptr };
GetShaderDefines(type, descriptor, &defines[1]);
if (!REL::Module::IsVR()) {
defines[1] = { nullptr, nullptr };
} else {
defines[1] = { "VR", nullptr };
defines[2] = { nullptr, nullptr };
}
GetShaderDefines(type, descriptor, &defines[(1 + (size_t)REL::Module::IsVR())]);

logger::debug("{}, {}", descriptor, MergeDefinesString(defines));

Expand Down Expand Up @@ -1273,7 +1270,8 @@ namespace SIE
RE::BSGraphics::VertexShader* ShaderCache::GetVertexShader(const RE::BSShader& shader,
uint32_t descriptor)
{
if (!ShaderCache::IsSupportedShader(shader)) {
auto state = State::GetSingleton();
if (!((ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() && state->IsShaderEnabled(shader)))) {
return nullptr;
}

Expand All @@ -1298,7 +1296,9 @@ namespace SIE
RE::BSGraphics::PixelShader* ShaderCache::GetPixelShader(const RE::BSShader& shader,
uint32_t descriptor)
{
if (!ShaderCache::IsSupportedShader(shader)) {
auto state = State::GetSingleton();
if (!(ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() &&
state->IsShaderEnabled(shader))) {
return nullptr;
}

Expand Down
21 changes: 20 additions & 1 deletion src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,23 @@ void State::SetLogLevel(spdlog::level::level_enum a_level)
spdlog::level::level_enum State::GetLogLevel()
{
return logLevel;
}
}

bool State::ShaderEnabled(const RE::BSShader::Type a_type)
{
auto index = static_cast<uint32_t>(a_type) + 1;
if (index && index < sizeof(enabledClasses)) {
return enabledClasses[index];
}
return false;
}

bool State::IsShaderEnabled(const RE::BSShader& a_shader)
{
return ShaderEnabled(a_shader.shaderType.get());
}

bool State::IsDeveloperMode()
{
return GetLogLevel() <= spdlog::level::debug;
}
28 changes: 28 additions & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,32 @@ class State

void SetLogLevel(spdlog::level::level_enum a_level = spdlog::level::info);
spdlog::level::level_enum GetLogLevel();

/*
* Whether a_type is currently enabled in Community Shaders
*
* @param a_type The type of shader to check
* @return Whether the shader has been enabled.
*/
bool ShaderEnabled(const RE::BSShader::Type a_type);

/*
* Whether a_shader is currently enabled in Community Shaders
*
* @param a_shader The shader to check
* @return Whether the shader has been enabled.
*/
bool IsShaderEnabled(const RE::BSShader& a_shader);

/*
* Whether developer mode is enabled allowing advanced options.
* Use at your own risk! No support provided.
*
* <p>
* Developer mode is active when the log level is trace or debug.
* </p>
*
* @return Whether in developer mode.
*/
bool IsDeveloperMode();
};
36 changes: 36 additions & 0 deletions src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ namespace Util
for (auto& i : Defines)
macros.push_back({ i.first, i.second });

if (REL::Module::IsVR())
macros.push_back({ "VR", "" });

if (!_stricmp(ProgramType, "ps_5_0"))
macros.push_back({ "PIXELSHADER", "" });
else if (!_stricmp(ProgramType, "vs_5_0"))
Expand All @@ -144,6 +147,12 @@ namespace Util
ID3DBlob* shaderBlob;
ID3DBlob* shaderErrors;

std::string str;
std::wstring path{ FilePath };
std::transform(path.begin(), path.end(), std::back_inserter(str), [](wchar_t c) {
return (char)c;
});
logger::debug("Compiling {} with {}", str, DefinesToString(macros));
if (FAILED(D3DCompileFromFile(FilePath, macros.data(), D3D_COMPILE_STANDARD_FILE_INCLUDE, Program, ProgramType, flags, 0, &shaderBlob, &shaderErrors))) {
logger::warn("Shader compilation failed:\n\n{}", shaderErrors ? (const char*)shaderErrors->GetBufferPointer() : "Unknown error");
return nullptr;
Expand Down Expand Up @@ -177,4 +186,31 @@ namespace Util

return nullptr;
}

std::string DefinesToString(std::vector<std::pair<const char*, const char*>>& defines)
{
std::string result;
for (const auto& def : defines) {
if (def.first != nullptr) {
result += def.first;
result += ' ';
} else {
break;
}
}
return result;
}
std::string DefinesToString(std::vector<D3D_SHADER_MACRO>& defines)
{
std::string result;
for (const auto& def : defines) {
if (def.Name != nullptr) {
result += def.Name;
result += ' ';
} else {
break;
}
}
return result;
}
}
2 changes: 2 additions & 0 deletions src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ namespace Util
std::string GetNameFromRTV(ID3D11RenderTargetView* a_rtv);
void SetResourceName(ID3D11DeviceChild* Resource, const char* Format, ...);
ID3D11DeviceChild* CompileShader(const wchar_t* FilePath, const std::vector<std::pair<const char*, const char*>>& Defines, const char* ProgramType, const char* Program = "main");
std::string DefinesToString(std::vector<std::pair<const char*, const char*>>& defines);
std::string DefinesToString(std::vector<D3D_SHADER_MACRO>& defines);
}