Jump to content

  • Log In with Google      Sign In   
  • Create Account

Variable index


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 thecheeselover   Members   -  Reputation: 330

Like
0Likes
Like

Posted 15 January 2012 - 06:33 PM

Hi,

I am a beginner with hlsl and I'd like to know if you actually can do something like this, which is setting a global variable's index with another global scalar variable:

int t = 5;
float g[t];

If you can't do something like this in hlsl, then can you change the array to a greater or lower number through xna?

Thank you Posted Image
Thecheeselover
Hide yo cheese! Hide yo wife!

Sponsor:

#2 ViperG   Members   -  Reputation: 206

Like
1Likes
Like

Posted 15 January 2012 - 07:26 PM

You can do something like this:

#define Global 5;

float g[Global];
int t = Global;
int z = Global;

Black Sky A Star Control 2/Elite like game

#3 MJP   Moderators   -  Reputation: 11368

Like
1Likes
Like

Posted 15 January 2012 - 10:59 PM

Arrays in HLSL need to have a length that is static at compile time. So in other words..
// You can do this...
static const uint ArraySize = 5
float Array[ArraySize];

// Or you can do this...
#define ArraySize 5
float Array[ArraySize];

// But you can't do this
uint ArraySize = 5; 
float Array[ArraySize];

Usually what you do, is you define the array to some maximum size and then set another variable to a value representing how many values to actually use from the array. Like this:
static const uint MaxValues = 5;
float Values[MaxValues];
uint NumValuesToUse;

Just be careful...depending on the shader profile you use the compiler's ability to represent loops in shader assembly may be limited.

#4 thecheeselover   Members   -  Reputation: 330

Like
0Likes
Like

Posted 16 January 2012 - 06:51 AM

Thank you both! :)
Hide yo cheese! Hide yo wife!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS