5

Both seems to be HLSL shader language, but what is the difference between them?

Does it matter to change .hlsl extension to .hlsli, or vise versa?

One of the article I found says that .hlsli file is not going into compilation, is it correct? (Too few articles talking about .hlsli, not confident about this...)

Is it good to go with only .hlsli file, or there should always be some .hlsl files?

It would be appreciative if anyone could tell the same/difference between them, and their usage as well. Thanks.

adayoegi
  • 117
  • 10

2 Answers2

4

.hlsl is a shader file (contains the shader declaration) while .hlsli is an include file (contains only declarations and macros, no actual shader structure)

Pop Catalin
  • 61,751
  • 23
  • 87
  • 115
  • Can we put everything in hlsli file? Just like sometimes people put function definitions in .h rather than in .cpp. – adayoegi Oct 23 '17 at 02:12
  • 1
    @adayoegi, no because hlsli is not a header file (it is not compiled by any tool, a header is) .. it's only meant to contain fragments of text to be included in a hlsl file. – Pop Catalin Oct 25 '17 at 11:26
  • @adayoegi you can force hlsli to be compiled (the extention is not that important in the end) but most tooling won't be your friend if you do. – Pop Catalin Oct 25 '17 at 11:29
  • 1
    You can put function definitions in hlsli files, the hlsli just gets copy pasted. – Tom Huntington Nov 14 '21 at 06:04
  • 1
    @TomHuntington is right. It's better to declare all common structs, cbuffers and I/O structs in a file called Common.hlsli for inclusion in all vertex and pixel shaders in the game. Similarly, all lighting functions can be stored just once in a file like Lighting.hlsli, ensuring you have a single source of truth for your lighting model, instead of variations of the same functions stored separately across different shaders. – Maico De Blasio Feb 26 '22 at 05:29
2

hlsli is the HLSL equivalent of the .h/.hpp header file of the compiled file .cpp in C++. As in C++ where .h files aren't compiled, they are included to the .cpp files and then the latter are compiled, so does the .hlsli files are included to the .hlsl files and then the .hlsl files are compiled.

KeyC0de
  • 4,728
  • 8
  • 44
  • 68