What is the difference between .hlsl and .hlsli?
Asked Answered
Z

2

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.

Zealotry answered 18/10, 2017 at 11:25 Comment(0)
H
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)

Hostelry answered 18/10, 2017 at 13:18 Comment(5)
Can we put everything in hlsli file? Just like sometimes people put function definitions in .h rather than in .cpp.Zealotry
@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.Hostelry
@Zealotry 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.Hostelry
You can put function definitions in hlsli files, the hlsli just gets copy pasted.Northwards
@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.Dirty
S
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.

Sprinkler answered 8/10, 2020 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.