ShaderGraph节点——UV

UV Nodes

Flipbook——动画:根据输入的UV创建动画或纹理帧动画的UV。平铺的贴片数量由输入的宽度和高度值定义。当前块的索引是由输入Tile的值定义的。

此节点可用于创建纹理动画功能,通常用于粒子效果和精灵,方法是向输入Tile提供时间( Time )并将输出输出到纹理采样器(Texture Sampler)的UV输入槽。

UV数据通常在0到1之间,从UV空间的左下角开始。这可以从UV预览的左下角的黑色值看到。由于Flipbook通常从左上角开始,参数Invert Y在默认情况下是启用的,但是您可以通过切换Invert X和Invert Y参数来改变Flipbook的方向。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Width Input Vector 1 None Amount of horizontal tiles
Height Input Vector 1 None Amount of vertical tiles
Tile Input Vector 1 None Current tile index
Out Output Vector 2 None Output UV value
Name Type Options Description
Invert X Toggle True, False If enabled tiles are iterated from right to left
Invert Y Toggle True, False If enabled tiles are iterated from top to bottom

 

float2 _Flipbook_Invert = float2(FlipX, FlipY);

void Unity_Flipbook_float(float2 UV, float Width, float Height, float Tile, float2 Invert, out float2 Out)
{
    Tile = fmod(Tile, Width * Height);
    float2 tileCount = float2(1.0, 1.0) / float2(Width, Height);
    float tileY = abs(Invert.y * Height - (floor(Tile * tileCount.x) + Invert.y * 1));
    float tileX = abs(Invert.x * Width - ((Tile - Width * floor(Tile * tileCount.x)) + Invert.x * 1));
    Out = (UV + float2(tileX, tileY)) * tileCount;
}

Polar Coordinates——极座标:将输入UV的值转换为极座标。在数学中,极座标系统是一个二维座标系统,其中平面上的每个点都是由与参考点的距离和与参考方向的角度决定的。

其结果是,输入到UV的x通道被转换为距离输入的中心(Center )的值指定的点的距离值,而相同输入的y通道被转换为围绕该点的旋转角度的值。

这些值可以分别由输入的径向标度和长度标度进行缩放。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Center Input Vector 2 None Center reference point
Radial Scale Input Vector 1 None Scale of distance value
Length Scale Input Vector 1 None Scale of angle value
Out Output Vector 2 None Output value
void Unity_PolarCoordinates_float(float2 UV, float2 Center, float RadialScale, float LengthScale, out float2 Out)
{
    float2 delta = UV - Center;
    float radius = length(delta) * 2 * RadialScale;
    float angle = atan2(delta.x, delta.y) * 1.0/6.28 * LengthScale;
    Out = float2(radius, angle);
}

Radial Shear——径向剪切:将类似于波的径向剪切翘曲效应应用于输入UV的值。翘曲效应的中心参考点由输入中心(Center )定义,翘曲效应的整体强度由输入强度值定义。输入偏移量可用于偏移结果的各个通道。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Center Input Vector 2 None Center reference point
Strength Input Vector 1 None Strength of the effect
Offset Input Vector 2 None Individual channel offsets
Out Output Vector 2 None Output UV value
void Unity_RadialShear_float(float2 UV, float2 Center, float Strength, float2 Offset, out float2 Out)
{
    float2 delta = UV - Center;
    float delta2 = dot(delta.xy, delta.xy);
    float2 delta_offset = delta2 * Strength;
    Out = UV + float2(delta.y, -delta.x) * delta_offset + Offset;
}

Rotate:将输入UV值旋转到一个参考点周围,参考点由输入中心根据输入旋转量定义。旋转角度的单位可以由参数单位来选择。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Center Input Vector 2 None Center point to rotate around
Rotation Input Vector 1 None Amount of rotation to apply
Out Output Vector 2 None Output UV value

Radians

void Unity_Rotate_Radians_float(float2 UV, float2 Center, float Rotation, out float2 Out)
{
    UV -= Center;
    float s = sin(Rotation);
    float c = cos(Rotation);
    float2x2 rMatrix = float2x2(c, -s, s, c);
    rMatrix *= 0.5;
    rMatrix += 0.5;
    rMatrix = rMatrix * 2 - 1;
    UV.xy = mul(UV.xy, rMatrix);
    UV += Center;
    Out = UV;
}

Degrees

void Unity_Rotate_Degrees_float(float2 UV, float2 Center, float Rotation, out float2 Out)
{
    Rotation = Rotation * (3.1415926f/180.0f);
    UV -= Center;
    float s = sin(Rotation);
    float c = cos(Rotation);
    float2x2 rMatrix = float2x2(c, -s, s, c);
    rMatrix *= 0.5;
    rMatrix += 0.5;
    rMatrix = rMatrix * 2 - 1;
    UV.xy = mul(UV.xy, rMatrix);
    UV += Center;
    Out = UV;
}

Spherize:将类似于鱼眼照相机镜头的球形翘曲效应应用于输入UV的值。翘曲效应的中心参考点由输入中心定义,翘曲效应的整体强度由输入强度值定义。输入偏移量可用于偏移结果的各个通道。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Center Input Vector 2 None Center reference point
Strength Input Vector 1 None Strength of the effect
Offset Input Vector 2 None Individual channel offsets
Out Output Vector 2 None Output UV value
void Unity_Spherize_float(float2 UV, float2 Center, float Strength, float2 Offset, out float2 Out)
{
    float2 delta = UV - Center;
    float delta2 = dot(delta.xy, delta.xy);
    float delta4 = delta2 * delta2;
    float2 delta_offset = delta4 * Strength;
    Out = UV + delta * delta_offset + Offset;
}

Tiling and Offset:平铺和偏移分别通过输入平铺和偏移来抵消输入UV的值。随着时间的推移,这通常用于详细地图和滚动纹理。

Triplanar:Triplanar是一种通过在世界空间中投射来生成uv和采样纹理的方法。输入的纹理被采样3次,每一次在世界的x轴、y轴和z轴上,结果信息被平面投影到模型上,由法线或表面角度混合。生成的uv可以用Tile 输入贴图缩放,最终的混合强度可以用输入混合(Blend)控制。可以通过覆盖输入位置(Position )和法线(Normal)来修改投影。这是常用的纹理大型模型,如地形,其中手工创作的UV座标将是有问题的或没有性能。

可以使用下拉类型切换输入纹理的预期类型。如果将法线设置为法线,则法线将转换为世界空间,从而可以构造新的切线,然后在输出之前将其转换回切线空间。

注意:这个节点只能在片段着色器阶段使用。

Name Direction Type Binding Description
Texture Input Texture None Input texture value
Sampler Input Sampler State None Sampler for input Texture
Position Input Vector 3 World Space Position Fragment position
Normal Input Vector 3 World Space Normal Fragment normal
Tile Input Vector 1 None Tiling amount for generated UVs
Blend Input Vector 1 None Blend factor between different samples
Out Output Vector 4 None Output value

Default

float3 Node_UV = Position * Tile;
float3 Node_Blend = pow(abs(Normal), Blend);
Node_Blend /= dot(Node_Blend, 1.0);
float4 Node_X = SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.zy);
float4 Node_Y = SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.xz);
float4 Node_Z = SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.xy);
float4 Out = Node_X * Node_Blend.x + Node_Y * Node_Blend.y + Node_Z * Node_Blend.z;

Normal

float3 Node_UV = Position * Tile;
float3 Node_Blend = max(pow(abs(Normal), Blend), 0);
Node_Blend /= (Node_Blend.x + Node_Blend.y + Node_Blend.z ).xxx;
float3 Node_X = UnpackNormal(SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.zy));
float3 Node_Y = UnpackNormal(SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.xz));
float3 Node_Z = UnpackNormal(SAMPLE_TEXTURE2D(Texture, Sampler, Node_UV.xy));
Node_X = float3(Node_X.xy + Normal.zy, abs(Node_X.z) * Normal.x);
Node_Y = float3(Node_Y.xy + Normal.xz, abs(Node_Y.z) * Normal.y);
Node_Z = float3(Node_Z.xy + Normal.xy, abs(Node_Z.z) * Normal.z);
float4 Out = float4(normalize(Node_X.zyx * Node_Blend.x + Node_Y.xzy * Node_Blend.y + Node_Z.xyz * Node_Blend.z), 1);
float3x3 Node_Transform = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
Out.rgb = TransformWorldToTangent(Out.rgb, Node_Transform);

Twirl:将类似于黑洞的旋转翘曲效应应用于输入UV的值。翘曲效应的中心参考点由输入中心定义,翘曲效应的整体强度由输入强度值定义。输入偏移量可用于偏移结果的各个通道。

Name Direction Type Binding Description
UV Input Vector 2 UV Input UV value
Center Input Vector 2 None Center reference point
Strength Input Vector 1 None Strength of the effect
Offset Input Vector 2 None Individual channel offsets
Out Output Vector 2 None Output UV value
void Unity_Twirl_float(float2 UV, float2 Center, float Strength, float2 Offset, out float2 Out)
{
    float2 delta = UV - Center;
    float angle = Strength * length(delta);
    float x = cos(angle) * delta.x - sin(angle) * delta.y;
    float y = sin(angle) * delta.x + cos(angle) * delta.y;
    Out = float2(x + Center.x + Offset.x, y + Center.y + Offset.y);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章