HLSL global variables

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Jan 07, 2010 at 14:47

Hi all,

How can I declare global temporaries (i.e. variables accessible to all functions within a shader) in HLSL?

Trying to do this the straightforward way gives a compiler error. The manual also mentions that global variables are considered uniforms (i.e. shader constants). Is there any way to declare them to be temporaries? Is there some convenient alternative approach? I’m trying to translate some C/C++ to HLSL…

Thanks,

Nicolas

2 Replies

Please log in or register to post a reply.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Jan 07, 2010 at 16:21

Shouldn’t the static modifier on a global be enough?

static - Mark a local variable so that it is initialized one time and persists between function calls. If the declaration does not include an initializer, the value is set to zero. A global variable marked static is not visible to an application.

.edit: just tried, static indeed seems to work :)

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Jan 08, 2010 at 13:00

Excellent, thanks!