add 'advanced' post-effect load configuration
This commit is contained in:
parent
9cc59c8848
commit
02a91e0b72
@ -11,7 +11,10 @@
|
||||
],
|
||||
"post-effects": [
|
||||
"default",
|
||||
"ssao"
|
||||
{
|
||||
"name": "ssao",
|
||||
"advanced": true
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
"gui/menubg",
|
||||
|
||||
@ -12,7 +12,7 @@ float calc_shadow() {
|
||||
}
|
||||
|
||||
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);
|
||||
int shadowIdx = a_distance > 128.0 ? 1 : 0;
|
||||
|
||||
|
||||
@ -147,14 +147,12 @@ void AssetsLoader::processPreload(
|
||||
add(tag, path, name);
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<AssetCfg> config = nullptr;
|
||||
map.at("path").get(path);
|
||||
switch (tag) {
|
||||
case AssetType::SOUND: {
|
||||
bool keepPCM = false;
|
||||
add(tag,
|
||||
path,
|
||||
name,
|
||||
std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM)));
|
||||
config = std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM));
|
||||
break;
|
||||
}
|
||||
case AssetType::ATLAS: {
|
||||
@ -164,13 +162,19 @@ void AssetsLoader::processPreload(
|
||||
if (typeName == "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;
|
||||
}
|
||||
default:
|
||||
add(tag, path, name);
|
||||
break;
|
||||
}
|
||||
add(tag, path, name, std::move(config));
|
||||
}
|
||||
|
||||
void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {
|
||||
|
||||
@ -40,8 +40,7 @@ struct LayoutCfg : AssetCfg {
|
||||
struct SoundCfg : AssetCfg {
|
||||
bool keepPCM;
|
||||
|
||||
SoundCfg(bool keepPCM) : keepPCM(keepPCM) {
|
||||
}
|
||||
SoundCfg(bool keepPCM) : keepPCM(keepPCM) {}
|
||||
};
|
||||
|
||||
enum class AtlasType {
|
||||
@ -51,8 +50,13 @@ enum class AtlasType {
|
||||
struct AtlasCfg : AssetCfg {
|
||||
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<
|
||||
|
||||
@ -132,8 +132,13 @@ assetload::postfunc assetload::posteffect(
|
||||
vertexSource,
|
||||
fragmentSource
|
||||
);
|
||||
bool advanced = false;
|
||||
if (settings) {
|
||||
advanced = dynamic_cast<const PostEffectCfg*>(settings.get())->advanced;
|
||||
}
|
||||
assets->store(
|
||||
std::make_shared<PostEffect>(std::move(program), params), name
|
||||
std::make_shared<PostEffect>(advanced, std::move(program), params),
|
||||
name
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@ -10,10 +10,11 @@ PostEffect::Param::Param(Type type, Value defValue)
|
||||
}
|
||||
|
||||
PostEffect::PostEffect(
|
||||
bool advanced,
|
||||
std::shared_ptr<Shader> shader,
|
||||
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() {
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
};
|
||||
|
||||
PostEffect(
|
||||
bool advanced,
|
||||
std::shared_ptr<Shader> shader,
|
||||
std::unordered_map<std::string, Param> params
|
||||
);
|
||||
@ -48,10 +49,15 @@ public:
|
||||
|
||||
void setParam(const std::string& name, const dv::value& value);
|
||||
|
||||
bool isAdvanced() const {
|
||||
return advanced;
|
||||
}
|
||||
|
||||
bool isActive() {
|
||||
return intensity > 1e-4f;
|
||||
}
|
||||
private:
|
||||
bool advanced = false;
|
||||
std::shared_ptr<Shader> shader;
|
||||
std::unordered_map<std::string, Param> params;
|
||||
float intensity = 0.0f;
|
||||
|
||||
@ -97,6 +97,7 @@ void PostProcessing::configureEffect(
|
||||
) {
|
||||
const auto& viewport = context.getViewport();
|
||||
|
||||
bool ssaoConfigured = false;
|
||||
if (!ssaoConfigured) {
|
||||
for (unsigned int i = 0; i < 64; ++i) {
|
||||
auto name = "u_ssaoSamples["+ std::to_string(i) + "]";
|
||||
@ -129,7 +130,9 @@ void PostProcessing::render(
|
||||
}
|
||||
int totalPasses = 0;
|
||||
for (const auto& effect : effectSlots) {
|
||||
totalPasses += (effect != nullptr && effect->isActive());
|
||||
totalPasses +=
|
||||
(effect != nullptr && effect->isActive() &&
|
||||
!(effect->isAdvanced() && gbuffer == nullptr));
|
||||
}
|
||||
|
||||
const auto& vp = context.getViewport();
|
||||
@ -163,6 +166,9 @@ void PostProcessing::render(
|
||||
if (effect == nullptr || !effect->isActive()) {
|
||||
continue;
|
||||
}
|
||||
if (effect->isAdvanced() && gbuffer == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto& shader = effect->use();
|
||||
configureEffect(context, shader, timer, camera, shadowMap);
|
||||
|
||||
|
||||
@ -76,5 +76,4 @@ private:
|
||||
|
||||
std::vector<glm::vec3> ssaoKernel;
|
||||
uint noiseTexture;
|
||||
bool ssaoConfigured = false;
|
||||
};
|
||||
|
||||
@ -366,7 +366,7 @@ void WorldRenderer::generateShadowsMap(
|
||||
glm::vec3 basePos = glm::floor(camera.position);
|
||||
shadowCamera = Camera(basePos, shadowMapSize);
|
||||
shadowCamera.near = 0.1f;
|
||||
shadowCamera.far = 800.0f;
|
||||
shadowCamera.far = 1000.0f;
|
||||
shadowCamera.perspective = false;
|
||||
shadowCamera.setAspectRatio(1.0f);
|
||||
|
||||
@ -375,7 +375,7 @@ void WorldRenderer::generateShadowsMap(
|
||||
t += 1.0f;
|
||||
}
|
||||
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(
|
||||
sunAngle,
|
||||
glm::radians(-45.0f),
|
||||
@ -383,7 +383,7 @@ void WorldRenderer::generateShadowsMap(
|
||||
);
|
||||
shadowCamera.updateVectors();
|
||||
|
||||
shadowCamera.position -= shadowCamera.front * 200.0f;
|
||||
shadowCamera.position -= shadowCamera.front * 300.0f;
|
||||
shadowCamera.position += shadowCamera.up * 10.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 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());
|
||||
@ -456,7 +456,7 @@ void WorldRenderer::draw(
|
||||
chunks->update();
|
||||
|
||||
static int frameid = 0;
|
||||
if (shadows && frameid % 3 == 0) {
|
||||
if (shadows) {
|
||||
if (frameid % 2 == 0) {
|
||||
generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user