VideoCommon: add milliseconds elapsed time value to pixel shaders as a uniform to be able to support animation effects in custom shaders
This commit is contained in:
parent
675544ec2b
commit
931a8aa413
|
@ -58,6 +58,8 @@ struct alignas(16) PixelShaderConstants
|
||||||
// For shader_framebuffer_fetch logic ops:
|
// For shader_framebuffer_fetch logic ops:
|
||||||
u32 logic_op_enable; // bool
|
u32 logic_op_enable; // bool
|
||||||
LogicOp logic_op_mode;
|
LogicOp logic_op_mode;
|
||||||
|
// For custom shaders...
|
||||||
|
u32 time_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(16) VertexShaderConstants
|
struct alignas(16) VertexShaderConstants
|
||||||
|
|
|
@ -406,6 +406,7 @@ void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
|
||||||
"\tbool blend_subtract_alpha;\n"
|
"\tbool blend_subtract_alpha;\n"
|
||||||
"\tbool logic_op_enable;\n"
|
"\tbool logic_op_enable;\n"
|
||||||
"\tuint logic_op_mode;\n"
|
"\tuint logic_op_mode;\n"
|
||||||
|
"\tuint time_ms;\n"
|
||||||
"}};\n\n");
|
"}};\n\n");
|
||||||
out.Write("#define bpmem_combiners(i) (bpmem_pack1[(i)].xy)\n"
|
out.Write("#define bpmem_combiners(i) (bpmem_pack1[(i)].xy)\n"
|
||||||
"#define bpmem_tevind(i) (bpmem_pack1[(i)].z)\n"
|
"#define bpmem_tevind(i) (bpmem_pack1[(i)].z)\n"
|
||||||
|
@ -869,6 +870,9 @@ void WriteCustomShaderStructImpl(ShaderCode* out, u32 num_stages, bool per_pixel
|
||||||
// Actual data will be filled out in the tev stage code, just set the
|
// Actual data will be filled out in the tev stage code, just set the
|
||||||
// stage count for now
|
// stage count for now
|
||||||
out->Write("\tcustom_data.tev_stage_count = {};\n", num_stages);
|
out->Write("\tcustom_data.tev_stage_count = {};\n", num_stages);
|
||||||
|
|
||||||
|
// Time
|
||||||
|
out->Write("\tcustom_data.time_ms = time_ms;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, int n,
|
static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, int n,
|
||||||
|
|
|
@ -447,5 +447,6 @@ void WriteCustomShaderStructDef(ShaderCode* out, u32 numtexgens)
|
||||||
out->Write("\tCustomShaderTevStage[16] tev_stages;\n");
|
out->Write("\tCustomShaderTevStage[16] tev_stages;\n");
|
||||||
out->Write("\tuint tev_stage_count;\n");
|
out->Write("\tuint tev_stage_count;\n");
|
||||||
out->Write("\tfloat4 final_color;\n");
|
out->Write("\tfloat4 final_color;\n");
|
||||||
|
out->Write("\tuint time_ms;\n");
|
||||||
out->Write("}};\n\n");
|
out->Write("}};\n\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,6 +266,9 @@ void WriteCustomShaderStructImpl(ShaderCode* out, u32 num_texgen, bool per_pixel
|
||||||
// Actual data will be filled out in the tev stage code, just set the
|
// Actual data will be filled out in the tev stage code, just set the
|
||||||
// stage count for now
|
// stage count for now
|
||||||
out->Write("\tcustom_data.tev_stage_count = num_stages;\n");
|
out->Write("\tcustom_data.tev_stage_count = num_stages;\n");
|
||||||
|
|
||||||
|
// Time
|
||||||
|
out->Write("\tcustom_data.time_ms = time_ms;\n");
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
PixelShaderUid GetPixelShaderUid()
|
PixelShaderUid GetPixelShaderUid()
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/DolphinAnalytics.h"
|
#include "Core/DolphinAnalytics.h"
|
||||||
|
#include "Core/HW/SystemTimers.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
|
|
||||||
#include "VideoCommon/AbstractGfx.h"
|
#include "VideoCommon/AbstractGfx.h"
|
||||||
|
@ -107,6 +108,8 @@ VertexManagerBase::~VertexManagerBase() = default;
|
||||||
bool VertexManagerBase::Initialize()
|
bool VertexManagerBase::Initialize()
|
||||||
{
|
{
|
||||||
m_frame_end_event = AfterFrameEvent::Register([this] { OnEndFrame(); }, "VertexManagerBase");
|
m_frame_end_event = AfterFrameEvent::Register([this] { OnEndFrame(); }, "VertexManagerBase");
|
||||||
|
m_after_present_event = AfterPresentEvent::Register(
|
||||||
|
[this](PresentInfo& pi) { m_ticks_elapsed = pi.emulated_timestamp; }, "VertexManagerBase");
|
||||||
m_index_generator.Init();
|
m_index_generator.Init();
|
||||||
m_custom_shader_cache = std::make_unique<CustomShaderCache>();
|
m_custom_shader_cache = std::make_unique<CustomShaderCache>();
|
||||||
m_cpu_cull.Init();
|
m_cpu_cull.Init();
|
||||||
|
@ -526,6 +529,13 @@ void VertexManagerBase::Flush()
|
||||||
auto& geometry_shader_manager = system.GetGeometryShaderManager();
|
auto& geometry_shader_manager = system.GetGeometryShaderManager();
|
||||||
auto& vertex_shader_manager = system.GetVertexShaderManager();
|
auto& vertex_shader_manager = system.GetVertexShaderManager();
|
||||||
|
|
||||||
|
if (g_ActiveConfig.bGraphicMods)
|
||||||
|
{
|
||||||
|
const double seconds_elapsed =
|
||||||
|
static_cast<double>(m_ticks_elapsed) / SystemTimers::GetTicksPerSecond();
|
||||||
|
pixel_shader_manager.constants.time_ms = seconds_elapsed * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
|
CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
|
||||||
// Calculate ZSlope for zfreeze
|
// Calculate ZSlope for zfreeze
|
||||||
const auto used_textures = UsedTextures();
|
const auto used_textures = UsedTextures();
|
||||||
|
|
|
@ -233,8 +233,10 @@ private:
|
||||||
bool m_allow_background_execution = true;
|
bool m_allow_background_execution = true;
|
||||||
|
|
||||||
std::unique_ptr<CustomShaderCache> m_custom_shader_cache;
|
std::unique_ptr<CustomShaderCache> m_custom_shader_cache;
|
||||||
|
u64 m_ticks_elapsed;
|
||||||
|
|
||||||
Common::EventHook m_frame_end_event;
|
Common::EventHook m_frame_end_event;
|
||||||
|
Common::EventHook m_after_present_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<VertexManagerBase> g_vertex_manager;
|
extern std::unique_ptr<VertexManagerBase> g_vertex_manager;
|
||||||
|
|
|
@ -105,6 +105,7 @@ vec4 custom_main( in CustomShaderData data )
|
||||||
|``tev_stages`` | CustomShaderTevStage[] | v1 | An array of TEV stages, the amount is specified by ``tev_stage_count`` |
|
|``tev_stages`` | CustomShaderTevStage[] | v1 | An array of TEV stages, the amount is specified by ``tev_stage_count`` |
|
||||||
|``tev_stage_count`` | uint | v1 | The count of TEV stages |
|
|``tev_stage_count`` | uint | v1 | The count of TEV stages |
|
||||||
|``final_color`` | vec4 | v1 | The final color generated by Dolphin after all TEV stages are executed |
|
|``final_color`` | vec4 | v1 | The final color generated by Dolphin after all TEV stages are executed |
|
||||||
|
|``time_ms`` | uint | v1 | The time that has passed in milliseconds, since the game was started. Useful for animating |
|
||||||
|
|
||||||
`CustomShaderLightData` is used to denote lighting data the game is applying when rendering the specific draw call. It has the following structure:
|
`CustomShaderLightData` is used to denote lighting data the game is applying when rendering the specific draw call. It has the following structure:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue