add 'advanced' post-effect load configuration
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user