8#include "graphics/shaders/outline_post_frag_spv.inc"
16Shader *createOutlineShader(Graphics *gfx) {
18 std::vector<uint32_t>
frag(outline_post_frag_spv, outline_post_frag_spv + outline_post_frag_spv_count);
19 Shader *sh = gfx->getBackendName() ==
"webgpu"
22 : gfx->newShaderFromSpv({},
frag);
23 if (!sh || !sh->gpuHandle)
25 sh->declareFloat(
"width");
26 sh->declareFloat(
"depthThreshold");
27 sh->declareFloat(
"depthSensitivity");
28 sh->declareFloat(
"normalThreshold");
29 sh->declareFloat(
"softness");
30 sh->declareFloat(
"colorR");
31 sh->declareFloat(
"colorG");
32 sh->declareFloat(
"colorB");
33 sh->declareFloat(
"texelW");
34 sh->declareFloat(
"texelH");
35 sh->declareFloat(
"nearZ");
36 sh->declareFloat(
"farZ");
37 sh->sendFloat(
"width", 1.f);
38 sh->sendFloat(
"depthThreshold", 0.3f);
39 sh->sendFloat(
"depthSensitivity", 0.f);
40 sh->sendFloat(
"normalThreshold", 0.35f);
41 sh->sendFloat(
"softness", 0.15f);
42 sh->sendFloat(
"colorR", 0.05f);
43 sh->sendFloat(
"colorG", 0.04f);
44 sh->sendFloat(
"colorB", 0.07f);
45 sh->sendFloat(
"texelW", 1.f / 256.f);
46 sh->sendFloat(
"texelH", 1.f / 256.f);
47 sh->sendFloat(
"nearZ", 0.1f);
48 sh->sendFloat(
"farZ", 100.f);
55 shader_ = createOutlineShader(gfx);
76 width_ = std::max(
width, 0.5f);
77 if (shader_) shader_->
sendFloat(
"width", width_);
83 depthThreshold_ = std::max(threshold, 0.f);
84 if (shader_) shader_->
sendFloat(
"depthThreshold", depthThreshold_);
90 depthSensitivity_ = std::max(sensitivity, 0.f);
91 if (shader_) shader_->
sendFloat(
"depthSensitivity", depthSensitivity_);
97 normalThreshold_ = std::clamp(threshold, 0.f, 2.f);
98 if (shader_) shader_->
sendFloat(
"normalThreshold", normalThreshold_);
104 softness_ = std::clamp(softness, 0.f, 1.f);
105 if (shader_) shader_->
sendFloat(
"softness", softness_);
111 nearZ_ = nearZ > 1e-4f ? nearZ : 0.1f;
112 farZ_ = farZ > nearZ_ ? farZ : nearZ_ + 1.f;
124 if (!shader_)
throw eve::Exception(
"Outline.setFloat: null shader");
129 if (!shader_)
throw eve::Exception(
"Outline.getFloat: null shader");
140 shader_->
sendFloat(
"texelW", 1.f /
float(std::max(
w, 1)));
141 shader_->
sendFloat(
"texelH", 1.f /
float(std::max(
h, 1)));
150 if (!hwDepth)
return false;
151 if (!worldNormal)
return false;
153 uploadCommon(gfx, hwDepth);
159 Color(1.f, 1.f, 1.f, 1.f));
168 const bool ok =
apply(gfx, hwDepth, worldNormal);
EVENGINE_API_FOUNDATION public API.
virtual int getWidth() const =0
Returns the width.
virtual int getHeight() const =0
Returns the height.
int getWidth() const
Returns the width.
virtual Canvas * getCanvas() const =0
Returns the canvas.
virtual void setCanvas(Canvas *canvas)=0
nullptr or this → screen. Switching flushes pending draws to the previous target.
int getHeight() const
Returns the height.
virtual void drawTexturedRectShaderDepth(Texture *color, Texture *depth, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Fullscreen/post draw sampling color at binding 0 and depth at binding 1 (hardware D32,...
float getColorG() const
Returns the color g.
void setWidth(float width)
Outline thickness in screen pixels (>= 0.5).
float getDepthSensitivity() const
Returns the depth sensitivity.
void setDepthThreshold(float threshold)
View-space depth discontinuity that starts a depth edge.
float getDepthThreshold() const
Returns the depth threshold.
float getWidth() const
Returns the width.
float getSoftness() const
Returns the softness.
void setFloat(const std::string &name, float value)
Sets the float.
void setNormalThreshold(float threshold)
Normal discontinuity (1 - dot(n, nN)) that starts a crease edge.
void setColor(float r, float g, float b)
Sets the color.
void setSoftness(float softness)
Smoothstep band used to fade edges (0 = hard, 1 = soft).
float getColorB() const
Returns the color b.
bool hasParam(const std::string &name) const
True when param.
Outline(Graphics *gfx)
Outline.
void setDepthSensitivity(float sensitivity)
Extra per-unit-distance depth tolerance (keeps outlines distance-consistent).
float getFloat(const std::string &name) const
Returns the float.
void setClip(float nearZ, float farZ)
Near/far used to linearize the hardware depth.
bool apply(Graphics *gfx, Texture *hwDepth, Texture *worldNormal)
Draw the outline over the currently bound canvas / screen. hwDepth is the D32 GBuffer (Vulkan NDC z),...
float getNormalThreshold() const
Returns the normal threshold.
float getColorR() const
Returns the color r.
bool applyTo(Graphics *gfx, Texture *hwDepth, Texture *worldNormal, Canvas *dest)
Applies to.
bool hasUniform(const std::string &name) const
void sendFloat(const std::string &name, float x)
int getFromVar(const std::string &name, void *data, size_t size) const
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
int getWidth() const
Returns the width.
int getHeight() const
Returns the height.
constexpr const char * kPostCommon
constexpr const char * kOutline
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
eve::Color Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...