简体   繁体   English

SpriteKit中的水效果使用模糊和阈值

[英]Water Effect in SpriteKit using blur and threshold

I am trying to make a water effect using SpriteKit similar to the answer in this link. 我正在尝试使用SpriteKit制作水效果,类似于此链接中的答案。 Water physics 水物理学

How can I add a blur effect and some sort of "threshold" filter to get that look? 如何添加模糊效果和某种“阈值”滤镜以得到那种外观?

I got the blur to work like this, but am not sure how to add a "threshold" filter. 我可以使模糊像这样工作,但是不确定如何添加“阈值”滤镜。

override func didMoveToView(view: SKView) {

    let effectNode = SKEffectNode()

    let circleOne = SKSpriteNode(imageNamed: "circle1")
    circleOne.position = CGPointMake(CGRectGetMidX(self.frame) - 20, CGRectGetMidY(self.frame))

    let circleTwo = SKSpriteNode(imageNamed: "circle1")
    circleTwo.position = CGPointMake(CGRectGetMidX(self.frame) + 40, CGRectGetMidY(self.frame))

    effectNode.filter = blur()

    effectNode.addChild(circleOne)
    effectNode.addChild(circleTwo)

    addChild(effectNode)
}

func blur() -> CIFilter {
    let filter = CIFilter(name: "CIGaussianBlur")
    filter!.setDefaults()
    filter!.setValue(NSNumber(float: 10.0), forKey: "inputRadius")
    return filter!
}

Thank you for your help! 谢谢您的帮助!

So I found this Threshold filter that seems to work pretty well. 因此,我发现此阈值过滤器似乎运行良好。

void main() {
lowp vec4 color = texture2D(u_texture,v_tex_coord);

if(color.w > 0.1) {
    color = vec4(251.0/255.0, 246.0/255.0, 0.0/255.0, 1.0);
} else {
    color = vec4(0.0, 0.0, 0.0, 0.0);
}

gl_FragColor = color; }

The frame rate is fairly terrible when I reach about 30-50 sprites colliding with each other unfortunately. 不幸的是,当我遇到约30-50个精灵时,帧速率相当糟糕。

In order to help out a little, I got rid of the blur and just made the actual sprite images blurred, but it didn't help too much. 为了帮助一点,我摆脱了模糊,只是使实际的精灵图像模糊了,但是并没有太大帮助。

I did some reading about SpriteKit's Box2d implementation, and unfortunately it seems to not be very efficient, so I might be stuck with it. 了一些关于SpriteKit的Box2d实现的文章,不幸的是,它似乎不是很有效,所以我可能会坚持下去。

If anyone has a better solution, I'd love to hear your thoughts! 如果有人有更好的解决方案,我很想听听您的想法!

Here's what its looking like so far. 这是到目前为止的样子。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM