0
\$\begingroup\$

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Nov 7, 2018 at 1:04
  • \$\begingroup\$ @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 \$\endgroup\$
    – Alaman18
    Commented Nov 7, 2018 at 16:49

2 Answers 2

0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ I wasn't aware that the swizzle node allowed you to do that - huge thanks \$\endgroup\$
    – Alaman18
    Commented Nov 7, 2018 at 17:12
-3
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ Can you explain how you'd apply this to "mask a vector output to one or two values" in the Source shader editor? \$\endgroup\$
    – DMGregory
    Commented Nov 7, 2018 at 1:05
  • \$\begingroup\$ idk, you want to get 1-2 outputs from 3 inputs? sounds like you want clamp or get rid of an axis. \$\endgroup\$
    – Jared
    Commented Nov 7, 2018 at 1:07
  • \$\begingroup\$ gamedev.stackexchange.com/questions/88110/… \$\endgroup\$
    – Jared
    Commented Nov 7, 2018 at 1:08
  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Nov 7, 2018 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .