bartosz.baczek
bartosz.baczek

Reputation: 1516

Strange way of declaring variables in hlsl

I found this example of implementing Phong lightning in hlsl. It is first snippet where I see that strange syntax where you declare variables in hlsl like here:

float3 materialEmissive : EMISSIVE;
float3 materialAmbient : AMBIENT;

In usual instead of EMISSIVE or AMBIENT I used to declare position in register like:

float3 materialEmissive : register(c0);
float3 materialAmbient : register(c1);

Why would I declare variables like in example from link? I checked DirectX documentation, but didn't find whether EMMISIVE or AMBIENT are some key words in hlsl.

Upvotes: 0

Views: 1133

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32587

In this case, EMISSIVE and AMBIENT are so called semantics. They describe what that variable should contain (and not where it is stored).

The shader compiler can access these semantics to create a handle for the variable. E.g. the Effect Framework and older versions of DirectX let you specify global variables by their semantic name. This decouples the actual shader implementation (i.e. the variable name) from its interface to the outside world (i.e. the semantics).

Upvotes: 2

Related Questions