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

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

问题描述

我有一张包含很多精灵的地图。我可以使用扩散阴影将材质添加到精灵中,而不是添加大量灯光。但这不会给我我想要的结果。

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.

您可以看到图像是由手电筒产生的。它正在通过开放空间最大限度地扩展其光线,并很快被街区阻止。

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.

这里是顶层的一个很好的例子。我们可以看到某种2D定向光吗?请注意,房屋内部的照明再次由手电筒产生。右侧的洞穴显示了如何处理光的更好示例。另外,请注意背景中的孔,这会产生一些额外的光线进入洞穴。

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.

您可以在此处清楚地看到问题。灯光会增加强度。由于某种原因,光线会在某些瓷砖周围形成方形的边缘。另外,很多灯会很快导致性能问题。

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.

我读到可以使用射线广播吗?要定位开放空间之类的东西?我根本没有着色器或游戏照明的经验。对于如何实现Terraria / Starbound照明效果,我想给出一个很好的解释。这并不意味着我要说的是光线投射。

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中,光可以传播一定数量的空气障碍。它逐渐消失为完全黑暗。在图形设置中,可以启用 Smooth Lightning ,这(显然)将平滑块上的闪电。

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.

注意:我喜欢一个有用的答案,但是请提供一个带有详细说明的链接。或在答案中提供带有源代码的解释或指向Unity文档的链接。我不想看到理论付诸实践。我很想知道如何在Unity中实现这种照明的答案。

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.

我还想知道是否有可能 NOT 使用Unity市场中的软件包。

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

看看类似的文章,这些文章的链接包含了有关光线投射的基础知识。但是没有任何关于如何在Unity中实现此目的的解释,也没有我想要达到的Terraria / Starbound效果的解释:

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:

制作像Terraria和Starbound一样的像素照明

如何实现Terraria / Starbound 2d照明?

例如,看一下该视频,获得了很好的印象二维光如何在Starbound中工作:

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.

我也发帖了。

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

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

推荐答案

我可以提及2d动态照明实现统一的2个主要要素。

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


  1. 用于2d照明的基本要素之一是< a href = https://assetstore.unity.com/packages/tools/particles-effects/2ddl-pro-2d-dynamic-lights-and-shadows-25933 rel = nofollow noreferrer> DDL灯,带有官方教程此处

  2. 最重要的是,Unity本身正在开发动态照明系统,该系统目前处于测试阶段(适用于2019.2)。 Unity推出了用于2d灯光的Lightweight RP软件包
  3. 。 。。。。。 >
  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天全站免登陆