使用 SDL 制作 2d 灯光效果
我想在用 SDL.NET(和 C#)编写的 2d 赛车上创建灯光效果。 psychs 灯光效果很简单:汽车头灯(经典圆锥光效果)。 有人知道我在哪里可以找到通过 SDL 进行灯光管理的示例吗?或者告诉我如何解决这个问题? 感谢您的支持!
更新:实际上我已经用 gimp 创建了一个模拟光的图像。 然后我将它加载到我的汽车精灵前面以模拟灯光。 但我不喜欢这种类型的方法......也许比光的运行时生成/模拟更有效!
i would like to create a light effect on a 2d car racing written in SDL.NET (and c#).
The psychs Light effect is simple: the car headlights (classic conic light effect).
Does somebody know where can i look for some example of light managemnt via SDL ? Or maybe tell me how to solve this issue ?
Thank you for your support !
Update: actually i've created an image with gimp with a simulation of light.
Then i load it in front of my car sprite to simulate the light.
But i don't like this type of approach... maybe is more efficient than a run-time generation/simulation of a light!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在寻找纯 2D 解决方案,您只需将车头灯精灵附加到您的汽车精灵上即可。这里没有“灯光管理”。只是一个 alpha 混合的精灵。
为了改善效果,您实际上可能需要创建并使用两个精灵:
注意:如果您可以在 SDL 中创建适当形状的 alpha 混合基元,则可以在没有图像的情况下执行第二个操作。
If you're looking at pure 2D solutions, you just want to attach the headlights sprite to your car sprite. There is no "light management" here. Just an alpha-blended sprite.
To improve the effect, you might want to create and use two sprites actually:
Note: you might do the second without images, if you can create an alpha-blended primitive in SDL of the proper shape.
如果您需要真实的光照模型,则必须更改为 opengl 或 directx 并使用延迟光照等着色器。 这是 xna 的示例。
If you need a realistic lighting model you have to change to opengl or directx and use a shader like deferred lighting. This is an example for xna.
使用多个图像怎么样?
由于 SDL 没有着色器效果,我建议根据您想要的细节将圆锥形图像分成小部分,并与图像前面的对象进行碰撞检查并仅绘制所需的部分。
这是一个技巧,但如果你垂直和水平地分割“发光”图像,它看起来会很好。
How about using multiple images instead?
Since SDL doesn't have shader effects, I would suggest breaking the conical image into small parts depending on the detail you want, and collision checking with the objects in front of the image and drawing only the parts required.
It's a hack, but it can look good if you divide the "glow" images both vertically and horizontally.