HLSL can be learned in 2 hours, but it takes many years to be proficient. I have never used define before. I read the xNa built-in effect source code to find that the Macros in HLSL are as powerful as they are, and I have seen the most crazy register binding, go directlyCodeRight :)
HLSL macro
# Ifdef sm4
// macros for targetting Shader Model 4.0 (dx11/10)
# define begin_constants cbuffer parameters: Register (B0) {
# define matrix_constants}; cbuffer projectionmatrix: Register (B1) {
# define end_constants};
# Define_ Vs (r)
# Define_ PS (r)
# Define_ CB (R): packoffset (r)
# DefineDeclare_texture (name, index )\
Texture2d<Float4>Name: Register (T # index );\
Sampler name # sampler: Register (s # index)
# DefineDeclare_cubemap (name, index )\
Texturecube<Float4>Name: Register (T # index );\
Sampler name # sampler: Register (s # index)
# DefineSample_texture (name, texcoord) name. Sample (name ## sampler, texcoord)
# DefineSample_cubemap (name, texcoord) name. Sample (name ## sampler, texcoord)
# else
// macros for targetting Shader Model 2.0/3.0 (DX9)
# define begin_constants
# define matrix_constants
# define end_constants
# define _vs (R ): register (Vs, R)
# define _ PS (R): Register (Ps, R)
# define _ CB (r)
# define declare_texture (name, index) \
texture2d name; \
sampler name # sampler: Register (s # index) = sampler_state {texture = (name) ;};
# DefineDeclare_cubemap (name, index )\
Texturecube name ;\
Sampler name # sampler: Register (s # index)=Sampler_state {texture=(Name );};
# DefineSample_texture (name, texcoord) tex2d (name ## sampler, texcoord)
# DefineSample_cubemap (name, texcoord) texcube (name ## sampler, texcoord)
# Endif
HLSL constant define
# Include " Macros. fxh "
Declare_texture (texture,0);
Begin_constants
float4 diffusecolor _ vs (C0) _ PS (C1) _ CB (C0);
float3 emissivecolor _ vs (C1) _ PS (C2) _ CB (C1);
float3 specularcolor _ vs (C2) _ PS (C3) _ CB (C2);
float specularpower _ vs (C3) _ PS (C4) _ CB (c2.w );
Float3 dirlight0direction _ vs (C4) _ PS (C5) _ CB (C3 );
Float3 dirlight0diffusecolor _ vs (C5) _ PS (C6) _ CB (C4 );
Float3 dirlight0specularcolor _ vs (C6) _ PS (C7) _ CB (C5 );
Float3 dirlight1direction _ vs (C7) _ PS (C8) _ CB (C6 );
Float3 dirlight1diffusecolor _ vs (C8) _ PS (C9) _ CB (C7 );
Float3 dirlight1specularcolor _ vs (C9) _ PS (C10) _ CB (C8 );
Float3 dirlight2direction _ vs (C10) _ PS (C11) _ CB (C9 );
Float3 dirlight2diffusecolor _ vs (C11) _ PS (C12) _ CB (C10 );
Float3 dirlight2specularcolor _ vs (C12) _ PS (C13) _ CB (C11 );
Float3 eyeposition _ vs (C13) _ PS (C14) _ CB (C12 );
Float3 fogcolor _ PS (C0) _ CB (C13 );
Float4 fogvector _ vs (C14) _ CB (C14 );
Float4x4 world _ vs (C19) _ CB (C15 );
Float3x3 worldinversetranspose _ vs (C23) _ CB (C19 );
Matrix_constants
Float4x4 worldviewproj _ vs (C15) _ CB (C0 );
End_constants