0
votes

It might be stupid question, but I was looking for a long time for an answer and I can't find one for my DirectX 11 game engine. For example I have got two pixel shaders A and B and I don't want to repeat my code for gamma correction. So my idea was to move that to separate hlsl file and include them, but I don't know how to do that. When I was google that I was only able to find informations about .fx workflow, but I'm not using it. When I'm trying to make a new shader I always get an error, that my shaders need to have main function. How can I do this?

EDIT: As VTT suggested I will provide example. Let's say I have my uber_pixel_shader.hlsl like this:

#include "gamma_utils_shader.hlsl"

...

float4 main(PS_INPUT input) : SV_TARGET
{
    ...
    finalColor = gammaCorrect(finalColor);

    return float4(finalColor, Alpha);
}

And there is no method gammaCorrect in HLSL, so I want to include it from another file named gamma_utils_shader.hlsl. This file looks like this:

float3 gammaCorrect(float3 inputColor)
{
    return pow(inputColor, 1.0f / 2.2f);
}

When I'm trying to compile this, the comipler is throwing an error "Error 3501 'main': entrypoint not found". And it's true, becase I don't have main method in this file, but I do not need one. How can I solve this in Visual Studio 2017?

1
Have you looked these links link1, link2, link3, link4Ben Souchet
I saw that, but I wasn't able to do that, because when I add new shader and just try to include it I get an error, due to missing main function.bilek993
hlsl #include directive, if you are getting an error then you should post mcveuser7860670
I have added more informations.bilek993
maybe you are trying to compile gamma_utils_shader.hlsl instead of just including it?user7860670

1 Answers

3
votes

Your project settings by default specify that an HLSL file should be compiled with the HLSL compiler. This means that during the build, VS queues all your HLSL files, including your include file, for compilation by the compiler with the default entrypoint of main. Obviously this is not desired - an include file can't be truly compiled.

To solve the issue, right click on your HLSL include file in the 'Solution Explorer', click 'Properties', and change the 'Item Type' field from "HLSL Compiler" to "Does not participate in build". This will prevent Visual Studio from compiling your include file.

In the future, provide the '.hlsli' extension to your HLSL include files. Visual Studio will open those files with the HLSL editor, but automatically identify them as not participating in the build procedure.