Home Technical Talk

Making an HLSL switch case for UDK?

Coexistence
polycounter lvl 7
Offline / Send Message
Coexistence polycounter lvl 7
I'm learning HLSL and I was hoping to use it to help me make a material in UDK. I'm trying to get a simple switch case to work in a custom material node, and even though I'm using the official HLSL reference, I can't seem to get it to work.

ivN3BeO

The image doesn't seem to be working here. Open it on a new tab or click here

Replies

  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 15
    what kind of error are you getting? Your code looks solid. You could alternatively try this.
    1. float4 finalValue = 0.0f; // The default value is now here.
    2.  
    3. switch (indexNum)
    4. {
    5. case 0:
    6. finalValue = 0.25f;
    7. break;
    8. case 1:
    9. finalValue = 0.5f;
    10. break;
    11. case 2:
    12. finalValue = 1.0f;
    13. break;
    14. }
    15.  
    16. return finalValue;

    Also try changing the default value from {0,0,0,0}; to simply
    1. float4 defaultValue = 0.0;
    2. float4 case1Value = 1.0;
    3.  
  • Coexistence
    Offline / Send Message
    Coexistence polycounter lvl 7
    I'm not getting any errors, but it won't return anything but the default.

    I plugged in your code and it seems to work. It might be because I didn't have decimal points in my float? Do I need the "f" after a float value?
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 20
    its probably the break statements he included.
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 15
    Vailias wrote: »
    its probably the break statements he included.

    No... Definitely works on my end :P

    Here it is slightly different, in case you want 0 to be the default value...
    1. float4 finalValue = 0.0f; // The default value is now here.
    2.  
    3. switch (indexNum)
    4. {
    5. case 1:
    6. finalValue = 0.25f;
    7. break;
    8. case 2:
    9. finalValue = 0.5f;
    10. break;
    11.  
    12. case 3:
    13. finalValue = 0.75f;
    14. break;
    15. }
    16.  
    17. return finalValue;

    And no, you don't need the decimal or the 'f' at the end. It's just a habit I have carried over from programming :P
Sign In or Register to comment.