失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 金庸笔下用脚发暗器_移动的艺术:使用明暗器图创建动画材质

金庸笔下用脚发暗器_移动的艺术:使用明暗器图创建动画材质

时间:2022-08-25 20:59:17

相关推荐

金庸笔下用脚发暗器_移动的艺术:使用明暗器图创建动画材质

金庸笔下用脚发暗器

In Unity .2 we added the “Vertex Position” input to Shader Graph, allowing you to adjust and animate your meshes. In this blog post, I’ll demonstrate how you can create your own vertex animation shaders, and provide some common examples such as a wind and a water shader.

在Unity .2中,我们向“着色器图”添加了“顶点位置”输入,使您可以调整和设置网格动画。 在此博客文章中,我将演示如何创建自己的顶点动画着色器,并提供一些常见示例,例如风和水着色器。

If you’re new to Shader Graph you can read Tim Cooper’s blog post to learn about the main features or watch Andy Touch’s “Shader Graph Introduction” talk on the Unity YouTube channel.

如果您是Shader Graph的新手,可以阅读Tim Cooper的博客文章以了解主要功能,或在Unity YouTube频道上观看Andy Touch的“ Shader Graph Introduction” 。

This scene does not use any textures or animation assets; everything you see is colored and animated using Shader Graph.

该场景不使用任何纹理或动画资源。使用“ Shader Graph”对所看到的所有内容进行着色和动画处理。

Shaders are an incredibly powerful aspect of the rendering pipeline, allowing a great degree of control over how our scene assets are displayed. Using a series of inputs and operations, we can create shaders that change the various rendering properties of our assets, such as their surface color and texture, and even the vertex positions of the mesh. You can also combine all of these into complex, rich animations. This blog post will demonstrate how you can get started with vertex animations, introduce the concept of using masks and properties, and finish by explaining how we made the shaders for the Desert Island Scene.

着色器是渲染管道中一个非常强大的方面,它可以极大地控制场景资源的显示方式。 使用一系列输入和操作,我们可以创建着色器,以更改资产的各种渲染属性,例如其表面颜色和纹理,甚至网格的顶点位置。 您还可以将所有这些组合成复杂的丰富动画。 该博客文章将演示如何开始使用顶点动画,介绍使用蒙版和属性的概念,并在最后解释我们如何制作“沙漠岛场景”的着色器。

下载示例项目 (Download the Example Project)

Clone Repository from GitHuborDownload .Zip from GitHub

从GitHub克隆存储库从GitHub下载.Zip

Download the Desert Island Scene sample project to start experimenting and interacting with the shaders yourself! This project contains everything you need to get started with Shader Graph. Ensure you launch the project using Unity version .2 or above.

下载Desert Island Scene示例项目,开始自己尝试和与着色器交互! 该项目包含开始使用Shader Graph所需的一切。 确保使用Unity版本.2或更高版本启动项目。

Every shader in the Desert Island Scene was built with customization in mind, so feel free to start playing around with the shader values in the Inspector! Each object also has a preset file that will return the values to default.

荒岛场景中的每个着色器都是在考虑自定义的基础上构建的,因此随时可以开始使用Inspector中的着色器值! 每个对象还具有一个预设文件 ,该文件会将值恢复为默认值。

This work is licensed under the Creative Commons Attribution 4.0 International License.

该作品已根据知识共享署名4.0国际许可协议获得许可 。

安装着色器图 (Install Shader Graph)

In order to use Shader Graph, your Project must meet the following requirements:

为了使用Shader Graph,您的项目必须满足以下要求:

Using either the new Lightweight or High Definition render pipelines (LWRP is suggested for experimentation due to faster compile times).

使用新的“ 轻量级”或“高清晰度”渲染管线 (建议使用LWRP进行实验,因为编译时间更快)。

To install Shader Graph, either create or update a Project to version .2 or above, navigate toWindow>Package Manager>All, findShader Graphin the list and click install.

要安装Shader Graph,请创建项目或将项目更新到版本.2或更高版本,导航至“窗口”>“包管理器”>“全部”,在列表中找到“Shader Graph”,然后单击“安装”。

If your materials are not animating in the Scene view, make sure you haveAnimated Materialschecked:

如果材质不在“场景”视图中设置动画,请确保已选中“动画材质”

Making something fancy with Shader Graph? You can preview Animated Materials by clicking the little picture drop down at the top left of the scene view #UnityTips #Unity3D /AwxQ5jj2Sg

使用Shader Graph做点什么? 您可以通过点击小图片预览动画材质,在离开现场视图顶部的下拉#UnityTips #Unity3D /AwxQ5jj2Sg

— John O’Reilly ? (@John_O_Really) July 17,

—约翰·奥雷利(John O'Reilly)? (@John_O_Really) 7月17日

顶点位置的基础 (The Basics of Vertex Position)

whatit is that we’re moving.什么。

A Mesh in the scene has four types of spaces:

场景中的网格具有四种类型的空间:

Object: Vertex position relative to the mesh pivot.

对象:相对于网格枢轴的顶点位置。

View: Vertex position relative to the camera.

视图:相对于摄影机的顶点位置。

World: Vertex position relative to the world origin.

世界:相对于世界原点的顶点位置。

Tangent: Addresses some special use cases, such as per-pixel lighting.

切线:解决一些特殊的用例,例如每像素照明。

You can select whichSpaceyou wish to affect in the dropdown of thePositionnode.

您可以在“位置”节点的下拉列表中选择希望影响的空间

Splitnode we can select which axis we want to affect.分割”节点,我们可以选择要影响的轴。

TheSplitnode outputs to four channels, the first three correspond to our Transform axis (R=X, G=Y, B=Z). In the example above, I’ve split out the y-axis of the object and added 1, moving our object up by 1 on its own axis.

“分割”节点输出到四个通道,前三个对应于我们的“变换”轴(R = X,G = Y,B = Z)。 在上面的示例中,我分割了对象的y轴并添加了1,将对象在其自身的轴上向上移动了1。

Sometimes you may wish to move the object in world space. To do this, selectWorldfrom thePositionnode, then convert the output back to object space using theTransformnode.

有时您可能希望在世界空间中移动对象。 为此,请从“位置”节点中选择“世界”,然后使用“变换”节点将输出转换回对象空间。

使用口罩 (Using Masks)

Now that we’ve established how to move a Mesh, it’s often useful to know how we can restrict the effect.

既然我们已经确定了如何移动网格物体,那么知道如何限制效果通常很有用。

By using nodes such asLerp, we can blend between two values. TheTInput is the control value for theLerp. When ourTinput is 0 (visualized as black), theAchannel is used. When our input is 1 (visualized as white), theBchannel is used. In the example below, the slider is used to blend between the two inputs. Any of the following examples can be used in place of the slider.

通过使用诸如Lerp之类的节点,我们可以在两个值之间进行混合。T输入是Lerp的控制值。 当我们的T输入为0(显示为黑色)时,将使用A通道。 当我们的输入为1(显示为白色)时,将使用B通道。 在下面的示例中,滑块用于在两个输入之间进行混合。 可以使用以下任何示例代替滑块。

纹理遮罩 (Texture Mask)

With a black and white texture, we can use detailed shapes to push our Mesh. In the above example, you can see how white represents the maximum height of our range, while black represents no effect on the Mesh position. This is because black has the numerical value of 0, and so adding 0 to the Mesh position doesn’t move it.

具有黑白纹理,我们可以使用详细的形状来推动“网格”。 在上面的示例中,您可以看到白色代表我们范围的最大高度,而黑色代表对网格位置没有影响。 这是因为黑色的数值为0,因此在“网格”位置添加0不会移动它。

To use a texture with vertex position, you must use theSample Texture 2D LODnodeinstead of the typicalSample Texture 2Dnode. Textures are particularly useful if you need a mask with a unique shape or a certain degree of falloff.

要使用具有顶点位置的纹理,必须使用“采样纹理2D LOD”节点而不是典型的“采样纹理2D”节点。 如果您需要具有独特形状或一定程度衰减的蒙版,则纹理特别有用。

紫外线面膜 (UV Mask)

While similar to a Texture mask, with a UV mask you can choose which part of the mesh you wish you affect based on the UV Unwrap. In the above screenshot, I’m using the u-axis of the UV to create a gradient from left to right. To offset the gradient, use anAddnode; to increase the strength, use aMultiplynode; and to increase the falloff, use aPowernode.

虽然与“纹理”蒙版类似,但是使用“ UV蒙版”可以基于“ UV展开”选择希望影响的网格部分。 在上面的屏幕截图中,我正在使用UV的U轴从左到右创建渐变。 要补偿渐变,请使用“添加”节点。 要增加强度,请使用“乘”节点; 并使用Power节点增加衰减。

顶点颜色蒙版(Vertex Colour Mask)

Each vertex stores a unit of Vector3 information that we refer to asVertex Colour. Using the Poly Brush package, we can directly paint vertex colors inside the editor. Alternatively, you can use 3D modeling software (such as 3ds Max, Maya, Blender, 3D Coat or Modo) to assign vertex colors. It is worth noting that, by default, most 3D modeling software will export models with the maximum value for RGB assigned to each vertex.

In the above screenshot, theVertex Colournode is split into the red (R) channel, then connected to theTchannel of theLerpnode, acting as a mask. TheAchannel of theLerpnode is used when the input is 0, with theBchannel being used when the input is 1. In practice, the above set up will only add 1 to the y-axis if the vertices have the red vertex color assigned.

每个顶点存储一个Vector3信息单元,我们将其称为“顶点颜色”。 使用Poly Brush包,我们可以在编辑器内直接绘制顶点颜色。 或者,您可以使用3D建模软件(例如3ds Max,Maya,Blender,3D Coat或Modo)来分配顶点颜色。 值得注意的是,默认情况下,大多数3D建模软件都会导出具有分配给每个顶点的RGB最大值的模型。

在上面的屏幕截图中,“顶点颜色”节点被拆分为红色(R)通道,然后连接到Lerp节点的T通道,用作遮罩。 当输入为0时,将使用Lerp节点的A通道,当输入为1时,将使用B通道。实际上,如果顶点具有红色顶点,则上述设置只会将y轴加1。颜色分配。

世界方向面具 (World Orientation Mask)

By using theNormal Vectornode, we can mask an input by the orientation of the Mesh faces. Again, theSplitnode allows us to select which axis we wish to affect (R=X, G=Y, B=Z). In the above screenshot, I mask using the y-axis, so that only the faces that face up are positive. It’s important to use aClampnode to discard any values that are not between 0 and 1.

通过使用法向矢量节点,我们可以通过网格面的方向来掩盖输入。 同样,“分割”节点允许我们选择希望影响的轴(R = X,G = Y,B = Z)。 在上面的屏幕截图中,我使用y轴进行了遮罩,因此只有正面朝上的脸是正的。 使用Clamp节点丢弃所有不在0到1之间的值很重要。

世界位置面具 (World Position Mask)

This series of nodes masks an input if the object’s position is above world position 0 on the y-axis.

如果对象的位置在y轴上的世界位置0上方,则该系列节点将掩盖输入。

物产 (Properties)

Properties allow us to modify the Shader’s values after the Shader has compiled. To create a property, click the+symbol in the Blackboard (pictured on the right). There are six types of properties:

属性允许我们在着色器编译后修改着色器的值。 要创建属性,请单击黑板中的+符号(如右图所示)。 有六种类型的属性:

应用实例 (Applied Examples)

挥着旗子 (Waving Flag)

Full resolution image

全分辨率图像

By outputting aGradient Noiseinto aStepfunction and then into theAlpha Clip Threshold, we can discard some pixels to tear the flag.

通过将“梯度噪声”输出到“阶跃”函数,然后输出到“Alpha剪辑阈值”,我们可以丢弃一些像素来撕裂该标志。

风草和棕榈叶 (Windy Grass and Palm Leaves)

The wind Shader uses world spaceGradient Noisepanning along a single axis to gently push and pull the leaves and grass.

风着色器使用世界空间沿单个轴平移渐变噪声来轻轻推动和拉动树叶和草丛。

Full resolution image

全分辨率图像

Using world position, we place aGradient Noiseacross the y-axis and x-axis. Using a Vector2, we can control the speed and direction at which it is offset.

使用世界位置,我们在y轴和x轴上放置了“渐变噪声”。 使用Vector2,我们可以控制其偏移的速度和方向。

Properties are used to control the density and strength of the offset. Subtracting 0.5 from theGradient Noiseensures that the Mesh is equally pushed and pulled.

属性用于控制胶印的密度和强度。 从“梯度噪声”中减去0.5可确保网格被均匀地推拉。

A UV mask is used to keep the base of the leaves and grass stationary. Finally, aTransformnode is used to convert the world position to object position.

紫外线面罩用于保持树叶和草的底部固定。 最后,使用“变换”节点将世界位置转换为对象位置。

y蛤 (Coy Clam)

Full resolution image

全分辨率图像

By inputting the GameObject’s position and the Camera position into theDistancenode, we can create a mask. TheOne Minusnode inverts the distance so that we have a positive value when we’re close to the clam. TheClampnode discards any values above 1 and below 0.

通过将GameObject的位置和Camera的位置输入到Distance节点,我们可以创建一个遮罩。 “一减”节点会反转距离,因此当我们靠近蛤we时,我们会得到一个正值。Clamp节点丢弃大于1且小于0的任何值。

ALerpnode is used to blend between the clam being shut and open. The Rotation is applied to the GameObject’s y-axis and z-axis. Rotating it around the x-axis.

Lerp节点用于在关闭和打开的蛤lam之间进行混合。 旋转应用于GameObject的y轴和z轴。 绕x轴旋转。

游鱼 (Swimming Fish)

In this Shader, we’re using a sine wave that’s generated across the object’s axis to make the fish wobble. We then mask off the head of the fish, so that the head stays still.

在此着色器中,我们使用沿对象轴生成的正弦波使鱼摆动。 然后,我们遮住鱼的头部,使头部保持静止。

Full resolution image

全分辨率图像

Generate a sine wave in object space along the y-axis and z-axis, with properties controlling the frequency and speed of the wave.

沿着y轴和z轴在对象空间中生成正弦波,并具有控制该波的频率和速度的属性。

Because we’re using both the x-axis and the y-axis, the fish wobbles along its width, and over its height.

因为我们同时使用x轴和y轴,所以鱼沿着其宽度和高度都摆动。

Use aLerpnode to mask off the front of the fish using the x-axis of the UV channel. By using aPowernode with a property, we can push the wobble effect to the back of the fish.

使用Lerp节点使用UV通道的x轴遮盖鱼的正面。 通过使用具有属性的Power节点,我们可以将摆动效果推到鱼尾。

海浪 (Ocean Waves)

Finally, we have the ocean Shader! This Shader offsets the top of the Mesh using three sine waves of different scales and angles. These sine waves are also used to generate the colours for the wave troughs and tips.

最后,我们有了海洋着色器! 此着色器使用三个不同比例和角度的正弦波来偏移网格的顶部。 这些正弦波也用于生成波谷和波峰的颜色。

Full resolution image

全分辨率图像

The three sine waves are then combined with twoAddnodes, and multiplied by a world scale gradient to break up the height of the wave tips. After this the combined, waves are added to the object position.

然后,将三个正弦波与两个“加”节点组合,然后乘以世界比例梯度以分解波尖的高度。 此后,将合并的波添加到对象位置。

产生正弦波 (Generating the Sine Waves)

Full resolution image

全分辨率图像

By Splitting out the x-axis and z-axis, we generate waves in two directions. The two multipliers are used to set the influence of each wave. For example, multiplying theZchannel by 0, would output a sine wave exclusively across the x-axis.

通过分解x轴和z轴,我们生成了两个方向的波。 两个乘数用于设置每个波的影响。 例如,将Z通道乘以0,将仅在x轴上输出正弦波。

Splitting out aWorld Positionnode to the x-axis and z-axis, and then combining them in a Vector2, gives us a UV space in world space. This orientates theGradient Noiseflat across the world. By adding this output to time, we offset the sine waves, helping break up the otherwise straight lines.

世界位置节点拆分为x轴和z轴,然后将它们组合到Vector2中,可以为我们提供世界空间中的UV空间。 这将在全球范围内定向“梯度噪声”平面。 通过将此输出与时间相加,我们抵消了正弦波,从而有助于打破了原本为直线的直线。

TheSinenode uses world space and time to generate a simple sine wave, to make the wave tips we use an absolute node to flip the negative values. TheOne Minusnode then inverts these values so that the wave tips are at the top.

正弦节点使用世界空间和时间来生成简单的正弦波,为使波尖产生,我们使用绝对节点来翻转负值。 然后,“一减”节点将这些值取反,以使波尖位于顶部。

进一步阅读 (Further Reading)

If you would like to know how to get started with Shader Graph, Andy Touch’s GDC talk is a great place to start. If you’re looking for other Shader Graph examples, Andy also has an Example Library available on GitHub.

如果您想知道如何开始使用Shader Graph, Andy Touch的GDC演讲是一个不错的起点。 如果您在寻找其他Shader Graph示例,Andy 在GitHub上还有一个示例库 。

For detailed documentation about Shader Graph, including descriptions of every node, go to the Shader Graph developer Wiki on GitHub. Get stuck in and join the conversation in our Graphics Experimental Previews forum! And finally, if you’re making something cool with Shader Graph, I’d love to see it! Feel free to reach out to me on Twitter @John_O_Really.

有关Shader Graph的详细文档,包括每个节点的描述 ,请访问GitHub上的Shader Graph开发人员Wiki 。 加入我们的“ 图形实验预览”论坛,加入对话! 最后,如果您要使用Shader Graph制作一些很棒的东西,我很乐意看到它! 随时通过Twitter @John_O_Really与我联系 。

翻译自: //10/05/art-that-moves-creating-animated-materials-with-shader-graph/

金庸笔下用脚发暗器

如果觉得《金庸笔下用脚发暗器_移动的艺术:使用明暗器图创建动画材质》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。