载入中...
搜索中...
未找到
Hd2dLook.cpp
浏览该文件的文档.
1#include "hd2d/Hd2d.h"
2
3#include "common/Exception.h"
4#include "graphics/Graphics.h"
6#include "graphics/Texture.h"
7
8#include <algorithm>
9#include <cmath>
10
11namespace eve::hd2d {
12
14 if (!std::isfinite(distance) || distance < 0.f)
15 throw eve::Exception("Hd2dLook.setFocusDistance: distance must be finite and >= 0");
16 focusDistance_ = distance;
17}
18
19void Hd2dLook::setMaxBlur(float blurPx) {
20 if (!std::isfinite(blurPx) || blurPx < 0.f)
21 throw eve::Exception("Hd2dLook.setMaxBlur: blur must be finite and >= 0");
22 maxBlurPx_ = std::min(blurPx, 32.f);
23}
24
26 if (!std::isfinite(range) || range <= 0.f)
27 throw eve::Exception("Hd2dLook.setFocusRange: range must be finite and > 0");
28 focusRange_ = range;
29}
30
31void Hd2dLook::setBloomIntensity(float intensity) {
32 if (!std::isfinite(intensity) || intensity < 0.f)
33 throw eve::Exception("Hd2dLook.setBloomIntensity: intensity must be finite and >= 0");
34 bloomIntensity_ = std::min(intensity, 8.f);
35}
36
37void Hd2dLook::setBloomThreshold(float threshold) {
38 if (!std::isfinite(threshold) || threshold < 0.f)
39 throw eve::Exception("Hd2dLook.setBloomThreshold: threshold must be finite and >= 0");
40 bloomThreshold_ = std::min(threshold, 16.f);
41}
42
44 if (!camera) throw eve::Exception("Hd2dLook.apply: null camera");
45 camera->setDepthOfField(focusDistance_, maxBlurPx_, focusRange_);
46 camera->setBloom(bloomIntensity_, bloomThreshold_);
47}
48
50 if (!gfx) throw eve::Exception("Hd2dLook.applyPixelSampler: null graphics");
51 if (!texture) throw eve::Exception("Hd2dLook.applyPixelSampler: null texture");
52 gfx->setTextureSampler(texture, "nearest", "none", 1.f, 0.f);
53}
54
56 Hd2dLook look;
57 look.focusDistance_ = 16.f;
58 look.maxBlurPx_ = 7.f;
59 look.focusRange_ = 12.f;
60 look.bloomIntensity_ = 0.45f;
61 look.bloomThreshold_ = 1.1f;
62 return look;
63}
64
66 Hd2dLook look;
67 look.focusDistance_ = 22.f;
68 look.maxBlurPx_ = 3.f;
69 look.focusRange_ = 18.f;
70 look.bloomIntensity_ = 0.2f;
71 look.bloomThreshold_ = 1.4f;
72 return look;
73}
74
75} // namespace eve::hd2d
float camera[2]
Range range
float distance
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
EVENGINE_API_BACKENDS public API.
virtual void setTextureSampler(Texture *texture, const std::string &filter, const std::string &mipmap, float maxAnisotropy, float lodBias)
Update sampler state without re-uploading pixels (filter / mip / aniso / LOD bias)....
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
HD-2D presentation look inspired by HD2DURP (DOF + bloom + pixel sampling).
Definition Hd2d.h:297
void setMaxBlur(float blurPx)
Max Gaussian blur radius in texels; 0 disables DOF (default 5).
Definition Hd2dLook.cpp:19
void setFocusRange(float range)
Distance from focus where blur reaches the max (default 14).
Definition Hd2dLook.cpp:25
void setBloomThreshold(float threshold)
HDR bloom threshold (default 1.2).
Definition Hd2dLook.cpp:37
void apply(graphics::Camera3D *camera) const
Write DOF + bloom onto a Camera3D (render-thread).
Definition Hd2dLook.cpp:43
void setFocusDistance(float distance)
View-space focus plane distance (default 18).
Definition Hd2dLook.cpp:13
static Hd2dLook soft()
Mild look with light bloom and modest DOF.
Definition Hd2dLook.cpp:65
static Hd2dLook miniature()
Strong miniature preset matching HD2DURP-style shallow DOF.
Definition Hd2dLook.cpp:55
void applyPixelSampler(graphics::Graphics *gfx, graphics::Texture *texture) const
Point-filter a texture for crisp pixel art (nearest / no mip).
Definition Hd2dLook.cpp:49
void setBloomIntensity(float intensity)
HDR bloom intensity (default 0.35).
Definition Hd2dLook.cpp:31