How to implement image stroke function??? #2941
Replies: 1 comment
-
//着色器测试
opts := &ebiten.DrawRectShaderOptions{}
opts.Uniforms = make(map[string]interface{})
opts.Uniforms["OutLine"] = []int32{1} //描边
opts.Uniforms["LineWidth"] = []float32{0.001} //线宽(左上角有问题,0.001可消除)
opts.Uniforms["LineColor"] = []float32{1.0, 1.0, 1.0, 1.0} //白色
opts.Images[0] = i.image
w, h := i.GetSize()
screen.DrawRectShader(w, h, i.shader, opts) package main
var OutLine int
var LineWidth float
var LineColor vec4
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
col := imageSrc0UnsafeAt(srcPos).rgba
if OutLine == 1 && col.a == 0.0 {
a := imageSrc0UnsafeAt(vec2(srcPos.x + LineWidth, srcPos.y)).a +
imageSrc0UnsafeAt(vec2(srcPos.x, srcPos.y - LineWidth)).a +
imageSrc0UnsafeAt(vec2(srcPos.x - LineWidth, srcPos.y)).a +
imageSrc0UnsafeAt(vec2(srcPos.x, srcPos.y + LineWidth)).a
if (a > 0.0){
col = vec4(LineColor.r,LineColor.g,LineColor.b,1.0)
}
}
return col * LineColor.a
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lsq51201314
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Operating System
What feature would you like to be added?
Most scenes in the game, such as when NPCS are selected, are highlighted with white Outlines
Why is this needed?
No response
Beta Was this translation helpful? Give feedback.
All reactions