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);
}

 

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