add 'advanced' post-effect load configuration

This commit is contained in:
MihailRis 2025-06-13 23:28:16 +03:00
parent 9cc59c8848
commit 02a91e0b72
10 changed files with 49 additions and 21 deletions

View File

@ -11,7 +11,10 @@
], ],
"post-effects": [ "post-effects": [
"default", "default",
"ssao" {
"name": "ssao",
"advanced": true
}
], ],
"textures": [ "textures": [
"gui/menubg", "gui/menubg",

View File

@ -12,7 +12,7 @@ float calc_shadow() {
} }
float step = 1.0 / float(u_shadowsRes); float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * 6.283185)), 0.7); // 2*PI precomputed float s = pow(abs(cos(u_dayTime * 6.283185)), 0.5); // 2*PI precomputed
vec3 normalOffset = a_realnormal * (a_distance > 128.0 ? 0.2 : 0.04); vec3 normalOffset = a_realnormal * (a_distance > 128.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 128.0 ? 1 : 0; int shadowIdx = a_distance > 128.0 ? 1 : 0;

View File

@ -147,14 +147,12 @@ void AssetsLoader::processPreload(
add(tag, path, name); add(tag, path, name);
return; return;
} }
std::shared_ptr<AssetCfg> config = nullptr;
map.at("path").get(path); map.at("path").get(path);
switch (tag) { switch (tag) {
case AssetType::SOUND: { case AssetType::SOUND: {
bool keepPCM = false; bool keepPCM = false;
add(tag, config = std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM));
path,
name,
std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM)));
break; break;
} }
case AssetType::ATLAS: { case AssetType::ATLAS: {
@ -164,13 +162,19 @@ void AssetsLoader::processPreload(
if (typeName == "separate") { if (typeName == "separate") {
type = AtlasType::SEPARATE; type = AtlasType::SEPARATE;
} }
add(tag, path, name, std::make_shared<AtlasCfg>(type)); config = std::make_shared<AtlasCfg>(type);
break;
}
case AssetType::POST_EFFECT: {
bool advanced = false;
map.at("advanced").get(advanced);
config = std::make_shared<PostEffectCfg>(advanced);
break; break;
} }
default: default:
add(tag, path, name);
break; break;
} }
add(tag, path, name, std::move(config));
} }
void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) { void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {

View File

@ -40,8 +40,7 @@ struct LayoutCfg : AssetCfg {
struct SoundCfg : AssetCfg { struct SoundCfg : AssetCfg {
bool keepPCM; bool keepPCM;
SoundCfg(bool keepPCM) : keepPCM(keepPCM) { SoundCfg(bool keepPCM) : keepPCM(keepPCM) {}
}
}; };
enum class AtlasType { enum class AtlasType {
@ -51,8 +50,13 @@ enum class AtlasType {
struct AtlasCfg : AssetCfg { struct AtlasCfg : AssetCfg {
AtlasType type; AtlasType type;
AtlasCfg(AtlasType type) : type(type) { AtlasCfg(AtlasType type) : type(type) {}
} };
struct PostEffectCfg : AssetCfg {
bool advanced;
PostEffectCfg(bool advanced) : advanced(advanced) {}
}; };
using aloader_func = std::function< using aloader_func = std::function<

View File

@ -132,8 +132,13 @@ assetload::postfunc assetload::posteffect(
vertexSource, vertexSource,
fragmentSource fragmentSource
); );
bool advanced = false;
if (settings) {
advanced = dynamic_cast<const PostEffectCfg*>(settings.get())->advanced;
}
assets->store( assets->store(
std::make_shared<PostEffect>(std::move(program), params), name std::make_shared<PostEffect>(advanced, std::move(program), params),
name
); );
}; };
} }

View File

@ -10,10 +10,11 @@ PostEffect::Param::Param(Type type, Value defValue)
} }
PostEffect::PostEffect( PostEffect::PostEffect(
bool advanced,
std::shared_ptr<Shader> shader, std::shared_ptr<Shader> shader,
std::unordered_map<std::string, Param> params std::unordered_map<std::string, Param> params
) )
: shader(std::move(shader)), params(std::move(params)) { : advanced(advanced), shader(std::move(shader)), params(std::move(params)) {
} }
Shader& PostEffect::use() { Shader& PostEffect::use() {

View File

@ -35,6 +35,7 @@ public:
}; };
PostEffect( PostEffect(
bool advanced,
std::shared_ptr<Shader> shader, std::shared_ptr<Shader> shader,
std::unordered_map<std::string, Param> params std::unordered_map<std::string, Param> params
); );
@ -48,10 +49,15 @@ public:
void setParam(const std::string& name, const dv::value& value); void setParam(const std::string& name, const dv::value& value);
bool isAdvanced() const {
return advanced;
}
bool isActive() { bool isActive() {
return intensity > 1e-4f; return intensity > 1e-4f;
} }
private: private:
bool advanced = false;
std::shared_ptr<Shader> shader; std::shared_ptr<Shader> shader;
std::unordered_map<std::string, Param> params; std::unordered_map<std::string, Param> params;
float intensity = 0.0f; float intensity = 0.0f;

View File

@ -97,6 +97,7 @@ void PostProcessing::configureEffect(
) { ) {
const auto& viewport = context.getViewport(); const auto& viewport = context.getViewport();
bool ssaoConfigured = false;
if (!ssaoConfigured) { if (!ssaoConfigured) {
for (unsigned int i = 0; i < 64; ++i) { for (unsigned int i = 0; i < 64; ++i) {
auto name = "u_ssaoSamples["+ std::to_string(i) + "]"; auto name = "u_ssaoSamples["+ std::to_string(i) + "]";
@ -129,7 +130,9 @@ void PostProcessing::render(
} }
int totalPasses = 0; int totalPasses = 0;
for (const auto& effect : effectSlots) { for (const auto& effect : effectSlots) {
totalPasses += (effect != nullptr && effect->isActive()); totalPasses +=
(effect != nullptr && effect->isActive() &&
!(effect->isAdvanced() && gbuffer == nullptr));
} }
const auto& vp = context.getViewport(); const auto& vp = context.getViewport();
@ -163,6 +166,9 @@ void PostProcessing::render(
if (effect == nullptr || !effect->isActive()) { if (effect == nullptr || !effect->isActive()) {
continue; continue;
} }
if (effect->isAdvanced() && gbuffer == nullptr) {
continue;
}
auto& shader = effect->use(); auto& shader = effect->use();
configureEffect(context, shader, timer, camera, shadowMap); configureEffect(context, shader, timer, camera, shadowMap);

View File

@ -76,5 +76,4 @@ private:
std::vector<glm::vec3> ssaoKernel; std::vector<glm::vec3> ssaoKernel;
uint noiseTexture; uint noiseTexture;
bool ssaoConfigured = false;
}; };

View File

@ -366,7 +366,7 @@ void WorldRenderer::generateShadowsMap(
glm::vec3 basePos = glm::floor(camera.position); glm::vec3 basePos = glm::floor(camera.position);
shadowCamera = Camera(basePos, shadowMapSize); shadowCamera = Camera(basePos, shadowMapSize);
shadowCamera.near = 0.1f; shadowCamera.near = 0.1f;
shadowCamera.far = 800.0f; shadowCamera.far = 1000.0f;
shadowCamera.perspective = false; shadowCamera.perspective = false;
shadowCamera.setAspectRatio(1.0f); shadowCamera.setAspectRatio(1.0f);
@ -375,7 +375,7 @@ void WorldRenderer::generateShadowsMap(
t += 1.0f; t += 1.0f;
} }
t = fmod(t, 0.5f); t = fmod(t, 0.5f);
float sunAngle = glm::radians(90.0f - (t + 0.25f) * 360.0f); float sunAngle = glm::radians(90.0f - (((int)(t*1000)) / 1000.0f + 0.25f) * 360.0f);
shadowCamera.rotate( shadowCamera.rotate(
sunAngle, sunAngle,
glm::radians(-45.0f), glm::radians(-45.0f),
@ -383,7 +383,7 @@ void WorldRenderer::generateShadowsMap(
); );
shadowCamera.updateVectors(); shadowCamera.updateVectors();
shadowCamera.position -= shadowCamera.front * 200.0f; shadowCamera.position -= shadowCamera.front * 300.0f;
shadowCamera.position += shadowCamera.up * 10.0f; shadowCamera.position += shadowCamera.up * 10.0f;
shadowCamera.position += camera.front * 100.0f; shadowCamera.position += camera.front * 100.0f;
@ -393,7 +393,7 @@ void WorldRenderer::generateShadowsMap(
auto min = view * glm::vec4(currentPos - (shadowCamera.right + shadowCamera.up) * (shadowMapSize * 0.5f), 1.0f); auto min = view * glm::vec4(currentPos - (shadowCamera.right + shadowCamera.up) * (shadowMapSize * 0.5f), 1.0f);
auto max = view * glm::vec4(currentPos + (shadowCamera.right + shadowCamera.up) * (shadowMapSize * 0.5f), 1.0f); auto max = view * glm::vec4(currentPos + (shadowCamera.right + shadowCamera.up) * (shadowMapSize * 0.5f), 1.0f);
shadowCamera.setProjection(glm::ortho(min.x, max.x, min.y, max.y, 0.1f, 800.0f)); shadowCamera.setProjection(glm::ortho(min.x, max.x, min.y, max.y, 0.1f, 1000.0f));
{ {
frustumCulling->update(shadowCamera.getProjView()); frustumCulling->update(shadowCamera.getProjView());
@ -456,7 +456,7 @@ void WorldRenderer::draw(
chunks->update(); chunks->update();
static int frameid = 0; static int frameid = 0;
if (shadows && frameid % 3 == 0) { if (shadows) {
if (frameid % 2 == 0) { if (frameid % 2 == 0) {
generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f); generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f);
} else { } else {