Hi,
I'm new to HLSL programming and although there are many nice hello-world type examples on the internet, it's difficult to know how I should be structuring my HLSL files.
For example I have a HLSL file called DrawImage which is just used for drawing 2D billboard-type images on-screen:
Texture2D image;
SamplerState Sampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
BlendState SrcAlphaBlendingAdd
{
BlendEnable[0] = TRUE;
SrcBlend = SRC_ALPHA;
DestBlend = INV_SRC_ALPHA;
BlendOp = ADD;
SrcBlendAlpha = ZERO;
DestBlendAlpha = ZERO;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0F;
};
struct VS_IN
{
float4 pos : POSITION;
float2 uv : TEXCOORD;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD;
};
PS_IN VS(VS_IN input)
{
PS_IN output = (PS_IN)0;
output.pos = input.pos;
output.uv = input.uv;
return output;
}
float4 PS(PS_IN input) : SV_Target
{
return image.Sample(Sampler, input.uv);
}
technique10 RenderImage
{
pass P0
{
SetGeometryShader( 0 );
SetVertexShader(CompileShader(vs_4_0, VS()));
SetPixelShader(CompileShader(ps_4_0, PS()));
SetBlendState(SrcAlphaBlendingAdd, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
technique10 RenderImageMirrored
{
pass P0
{
...
}
}
technique10 RenderImageNegative
{
pass P0
{
...
}
}
As you can see I've got a number of techniques related to drawing images in this file: RenderImage, RenderImageMirrored, RenderImageNegative (these are just for illustration btw, in my real application the transformations are more complex).
Thing is, all of the information I can find about HLSL techniques say they should be used to alter rendering depending on the capabilities of the platform. I'm using techniques because once one has compiled the HLSL into an effect, it's easy to find a technique (slimdx):
EffectTechnique technique = effect.GetTechniqueByName("RenderImageNegative");
The reason I'm placing all of these functions into one HLSL file is that the 'image' will be set once and used multiple times during a frame. Should I be using something else here, or arranging my HLSL code differently?