# Extracting individual components of a vector in the Source Shader Editor

I'm using the Source Shader editor and would like to mask a vector output to one or two values, yet there is no existing mask node, as far as I can see.

What HLSL code should I use to output what I need? The input would be in the format "x y z". Any help would be greatly appreciated

• Can you describe what you mean by "mask" in this context? We use that term to mean a few different things, even just within graphics contexts, so a little extra description can help make sure you get accurate, useful answers. – DMGregory Nov 7 '18 at 1:04
• @DMGregory I mean mask in the sense that - say I had a vector with the value 1.01 5.00 3.56, and representing these 3 values are X Y Z respectively - I'm looking to be able to split this into 3 seperate variables. The C++ equivalent of it would be something similar to #include <iostream> using namespace std; int main() { str x, y, z; cin >> x >> y >> z; return 0; } if that helps at all – Alaman18 Nov 7 '18 at 16:49

It sounds like you might be looking for the Swizzle node. According to Valve's documentation:

Swizzle (Vectors)

Uses arbitrary swizzling on a vector. You can also swizzle with constants and change the vector dimensions as you see fit. Use the properties dialog to define the swizzle operation, supports token channels.

So to take an input vector (x, y, z) and select just the y component, you'd place a Swizzle node by right-clicking and selecting New node -> Math (Vectors) -> Swizzle, then double-click it to access its properties and enter the string "y" to output just the y component as its own pin.

You can add additional Swizzle nodes to split out the x and z components too, to have three separate paths in your graph for the three components of the vector.

• I wasn't aware that the swizzle node allowed you to do that - huge thanks – Alaman18 Nov 7 '18 at 17:12

try using a float3 since that is the way to get x y z into a shader

• Can you explain how you'd apply this to "mask a vector output to one or two values" in the Source shader editor? – DMGregory Nov 7 '18 at 1:05
• idk, you want to get 1-2 outputs from 3 inputs? sounds like you want clamp or get rid of an axis. – Jared Nov 7 '18 at 1:07
• gamedev.stackexchange.com/questions/88110/… – Jared Nov 7 '18 at 1:08
• If you don't know, then it might be a bit premature to post an answer. Sometimes it's best to wait for the asker to clarify what they need, to ensure our answers are on-target and useful to them. – DMGregory Nov 7 '18 at 1:08