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++
    Options
    Offline / Send Message
    Drew++ polycounter lvl 14
    what kind of error are you getting? Your code looks solid. You could alternatively try this.
        float4 finalValue = 0.0f; // The default value is now here.
    
        switch (indexNum)
        {
        case 0: 
            finalValue = 0.25f;
            break;
            
        case 1: 
            finalValue = 0.5f;
            break;
            
        case 2: 
            finalValue = 1.0f;
            break;
        }
    
        return finalValue;
    

    Also try changing the default value from {0,0,0,0}; to simply
    float4 defaultValue = 0.0;
    float4 case1Value = 1.0;
    
    
  • Coexistence
    Options
    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
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    its probably the break statements he included.
  • Drew++
    Options
    Offline / Send Message
    Drew++ polycounter lvl 14
    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...
        float4 finalValue = 0.0f; // The default value is now here.
    
        switch (indexNum)
        {       
        case 1:
            finalValue = 0.25f;
            break;
            
        case 2:
            finalValue = 0.5f;
            break;
    
        case 3:
            finalValue = 0.75f;
            break;
        }
    
        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.