简体   繁体   English

如何使用 Unity Shader Graph 遮罩纹理

[英]How to mask a texture with Unity Shader Graph

So the final effect that am trying to achieve can be found in this tutorial video (unity shader lab) and my case i want to reach this result:所以我试图达到的最终效果可以在本教程视频(统一着色器实验室)中找到,我的情况是我想达到这个结果: 在此处输入图像描述

So far i created these properties:到目前为止,我创建了这些属性:

在此处输入图像描述

And the result is this (no idea why "tiling" has 4 fields even though its a Vector2):结果是这样的(不知道为什么“平铺”有 4 个字段,即使它是 Vector2):

在此处输入图像描述

After that, i added 2 new properties:之后,我添加了 2 个新属性:

在此处输入图像描述

A tiline and Offset node which has its offset controlled by the Position property, plugged it to a Sample Texture, and multiplied the output with the Emission texture output, and plugged the result to the Emission inpute of the PBR node:一个 tiline 和 Offset 节点,其偏移量由 Position 属性控制,将其插入到 Sample Texture,并将输出与 Emission 纹理输出相乘,并将结果插入 PBR 节点的 Emission 输入:

在此处输入图像描述

and the result is this:结果是这样的: 在此处输入图像描述

It's kinda giving me what i want but its far from finished, what i can't figure out is:它有点给了我我想要的东西,但它远未完成,我不知道的是:

  1. How to resize the mask area?如何调整遮罩区域的大小? because for now if i change the Tiling then the result is just too wrong:因为现在如果我改变 Tiling 那么结果就太错误了:

在此处输入图像描述

  1. Is my "positioning" logic correct ?我的“定位”逻辑正确吗? eventually i want the Position property to be controlled with a C# script based on a game object position, as you saw in my main preview example, i basically want the grid to glow under specific object, so am i doing it right ?最终我希望使用基于游戏对象位置的 C# 脚本来控制 Position 属性,正如您在我的主要预览示例中看到的那样,我基本上希望网格在特定对象下发光,所以我做得对吗?

Thanks a lot in advance!提前非常感谢! i really hope the Shader graph community start getting bigger cause its been super hard to find answers even for the the most basic things.我真的希望着色器图形社区开始变得更大,因为即使是最基本的事情也很难找到答案。

Have a nice day!祝你今天过得愉快!

尝试将纹理的包裹模式设置为钳制,而不是在导入设置中重复。

@user40079 was't wrong, he/she just didn't tell you which texture needs to be clamped. @user40079 没有错,他/她只是没有告诉你需要夹住哪个纹理。 I think mask texture need to be clamped to achieve what you want.我认为遮罩纹理需要被夹紧才能达到你想要的效果。

Here is my graph.这是我的图表。

统一的网格着色器图示例

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

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