如何实现 Terraria/Starbound 2d 光照? [英] How to achieve Terraria/Starbound 2d lighting?

查看:30
本文介绍了如何实现 Terraria/Starbound 2d 光照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以 Terraria/Starbound 的视角制作 2d 游戏.我希望照明看起来类似于:

I am making a 2d game in the perspective of Terraria/Starbound. I want the lighting to look similar to this:

我尝试通过在游戏中的所有精灵上添加材质然后给它们一个精灵漫反射着色器来获得这样的照明.然后我在需要光线的地方制作了点光源.但这有两个问题:1) 在光线最强烈的地方,它会消耗精灵的颜色并使其更亮.2) 我注意到 FPS 大幅下降(而且我只有 1 个点光源!).

Ive tried to get lighting like this by adding a material on all the sprites in my game and then giving them a sprite diffuse shader. Then I made a point light wherever I needed light. There where two problems with this though: 1) Where the light was most intense, it was draining the color of a sprite and made it lighter. 2) I noticed a big FPS drop (And I only had 1 point light!).

有没有什么方法可以实现这样的照明而无需编写自己的照明引擎?我搜索了资产商店,也搜索了 unity 是否可以从这个角度处理 2D 光照,但我什么也没找到.

Is there any way of achieving lighting like this without having to write my own lighting engine? Ive search the asset store and Ive searched to see if unity has any way of handing 2D lighting from this angle but I have found nothing.

如果我必须编写自己的照明引擎,对于刚接触 Unity 并且只有大约 8 个月经验的人来说,这会很复杂吗?

If I do have to write my own lighting engine, would that be to complex for someone who is relatively new to unity and has only had ~ 8 months experience?

推荐答案

假设您使用的是瓦片地图.

Assume you are using tile map.

你需要有一个视野图,可以通过阅读这个来实现:http://www.redblobgames.com/articles/visibility/

You need to have a field of view map, which can be achieved by reading this: http://www.redblobgames.com/articles/visibility/

使用此类地图,您可以准确了解每个图块的颜色.现在,只需将颜色混合到地图上每个图块的 SpriteRenderer.

Using such map, you know exactly the color tinting for each tile. Now, just blend the color to the SpriteRenderer of every tile on the map.

有人已经创建了一个视线插件:http://forum.unity3d.com/threads/light-of-sight-2d-dynamic-lighting-open-source.295968/

Somebody already created a line of sight plugin: http://forum.unity3d.com/threads/light-of-sight-2d-dynamic-lighting-open-source.295968/

这篇关于如何实现 Terraria/Starbound 2d 光照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆