HLSL global variables

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…



2 Replies

Please log in or register to post a reply.

_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 :)

Nick 102 Jan 08, 2010 at 13:00

Excellent, thanks!