Unity - 2D 着色器/照明,如 Terraria 或 Starbound [英] Unity - 2D shader / lighting like Terraria or Starbound

查看:24
本文介绍了Unity - 2D 着色器/照明,如 Terraria 或 Starbound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张包含很多精灵的地图.我可以使用漫反射着色为精灵添加材质,而不是添加大量灯光.但这不会给我想要的结果.而且性能很重.

<小时>

示例

在第一张图片中,您可以看到光是由手电筒产生的.它通过开放空间"以最佳方式扩展其光线,并且很快被方块挡住.

<小时>

这是顶层的一个很好的例子.我们可以看到某种二维定向光吗?请注意,屋内的照明再次由手电筒产生.右侧的洞穴展示了如何处理光线的更好示例.另外,请注意背景中的洞,这会产生一些额外的光线进入洞穴.好像光线真的透过那里的背景照进来一样.

<小时>

我有什么

您可以在这里清楚地看到问题.灯光会增加它们的强度.由于某种原因,光线会在一些瓷砖周围形成方形边缘.此外,大量灯光会很快导致性能问题.

<小时>

光线投射?

我读到你可以以某种方式使用光线投射?以开放空间"为目标?我完全没有使用着色器或游戏中的照明的经验.我很想得到一个关于如何实现这种泰拉瑞亚/星界之旅灯光效果的解释清楚的答案.这并不意味着我说光线投射是解决方案.

<小时>

我的世界

在 Minecraft 中,光可以传播一定数量的空气块.它逐渐消失到完全黑暗.在图形设置中,您可以启用 Smooth Lightning,这将(显然)平滑块上的闪电.

我想这是用着色器完成的,但我不确定.我的猜测是这对性能很重要.但我正在考虑空气块(它们是游戏对象),也许我的逻辑有误.

<小时>

注意:我喜欢有帮助的答案,但请提供包含详细说明的链接.或者在您的答案中提供带有源代码或 Unity 文档链接的解释.我不希望看到理论成功或其他什么.我很想知道如何在 Unity 中实现这种照明.

我还想知道是否可以使用来自 Unity Marketplace 的软件包.

<小时>

类似,但不好

查看类似的帖子,其中包含介绍光线投射基础知识的文章的链接.但没有解释如何在 Unity 中实现这一点,而不是我想要实现的 Terraria/Starbound 效果:

​​让像素光照像 terraria 和 starbound

Terraria/Starbound 2d 光照如何实现?><小时>

视频展示

例如,观看此视频,对 Starbound 中的 2d 光如何工作有一个非常好的印象:

https://www.youtube.com/watch?v=F5d-USf69SU

我知道这有点高级,但玩家手电筒产生的点光源也会被方块挡住,而被空地允许通过.

<小时>

其他帮助论坛

也是我发的.

Gamedev Exchange: ​​https://gamedev.stackexchange.com/questions/155440/unity-2d-shader-lighting-like-terraria-or-starbound

Unity 论坛: https://answers.unity.com/questions/1480518/2d-shader-lighting-like-terraria-or-starbound.html

<小时>

解决方案

我可以提到关于 2d Dynamic Lighting 的 2 个主要元素.

  1. Unity Essentials 中用于 2d 照明的主要资产之一是 DDL 灯,附有官方教程 此处.
  2. 最重要的是,Unity 本身正在开发动态光照系统,目前处于测试阶段(2019.2).Unity 为 2d 灯引入了 Lightweight RP 包 此处 以及此处的教程.

I have a map with a lot of sprites. I could add a material to the sprite with diffuse shading and than add lots of lights. But that won't give me the result I want. And is performance heavy.


Examples

In the first image you can see that light is generated by torches. It's expanding its light at its best through 'open spaces' and it is stopped by blocks fairly quickly.


Here is a great example of the top layer. We can see some kind of 2D directional light? Please note that the lighting inside the house is generated by torches again. The cave on the right side shows a better example of how light is handled. Also, note the hole in the background, this is generating some extra light into the cave. As if the light is really shining through the background there.


What I have

You can clearly see the issue here. Lights increase their intensity. And light creates a squared edge around some of the tiles for some reason. Also, lots of lights will cause performance issues very quickly.


Raycasting?

I read that you can somehow use raycasting? To target 'open space' or something? I have no experience with shaders or with lighting in games at all. I'd love a well-explained answer with how to achieve this Terraria/Starbound lighting effect. This does not mean I'm saying that raycasting is the solution.


Minecraft

In Minecraft, light can travel for a certain amount of air blocks. It gradually fades to completely dark. In the Graphic settings you can enable Smooth Lightning, which will (obviously) smooth the lightning on the blocks.

I guess this is done with shaders, but I'm not sure. My guess is that this is performance heavy. But I'm thinking about air blocks (which are gameobjects) and maybe I have the wrong logic.


Note: I love a helpful answer, but please provide a link with a detailed explanation. Or provide an explanation with source code or links to the Unity docs in your answer. I wouldn't like to see theories worked out or something. I'd love to get an answer on how to implement this kind of lighting in Unity.

I'd also like to know if it's possible to NOT use a package from the Unity Marketplace.


Similar, but no good

Take a look at similar posts with links to articles that cover the basics of raycasting. But no explanation on how to implement this in Unity and not the Terraria/Starbound effect I'd like to achieve:

Make pixel lighting like terraria and starbound

How to achieve Terraria/Starbound 2d lighting?


Video impression

For example, take a look at this video for a really good impression on how 2d light works in Starbound:

https://www.youtube.com/watch?v=F5d-USf69SU

I know this is a bit more advanced, but also the point light generated by the player's flash light is stopped by blocks and let through by the open spaces.


Other help forums

Also posted by me.

Gamedev Exchange: https://gamedev.stackexchange.com/questions/155440/unity-2d-shader-lighting-like-terraria-or-starbound

Unity Forum: https://answers.unity.com/questions/1480518/2d-shader-lighting-like-terraria-or-starbound.html


解决方案

I can mention 2 main elements about 2d Dynamic Lighting for unity.

  1. One of the main asset used for 2d lighting in unity essentials is DDL light, with an official tutorial here.
  2. Most importantly Unity itself is working on a Dynamic lighting system, currently in beta (for 2019.2). Unity introduced the package Lightweight RP for 2d lights here and there's a tutorial here.

这篇关于Unity - 2D 着色器/照明,如 Terraria 或 Starbound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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