Kurzmitteilung

Compiling HLSL Shader with premake5

I guess a lot of you that use premake often already know this, but since I find this to be handy I want to share it. A couple of days ago I needed to get shaders up and running in a very simple way. I started out by using the obligatory methods from the DirectX Api:

D3DCompileFromFile or the alternative D3DCompileToBlob. I still employ these methods however instead of compiling the file at runtime I decided to load pre-compiled shaders for now.

Since I don’t want to compile shaders manually each time I compile the project I looked for a solution that can be used with premake5. Everything I write I’ve found at https://stackoverflow.com/questions/55055150/premake5-how-to-build-hlsl-shaders. For an in depth look navigate to the link.

How does it work?

Navigate to your main premake5.lua script file and open it. Add the following lines of code to your project section.

shadermodel("5.0")

   shaderassembler("AssemblyCode")
   local shader_dir = "../Assets/Shader/"

   -- HLSL files that don't end with 'Extensions' will be ignored as they will be
   -- used as includes
   filter("files:**.hlsl")
     flags("ExcludeFromBuild")
     shaderobjectfileoutput(shader_dir.."%{file.basename}"..".cso")
     shaderassembleroutput(shader_dir.."%{file.basename}"..".asm")

   filter("files:**_ps.hlsl")
     removeflags("ExcludeFromBuild")
     shadertype("Pixel")

   filter("files:**_vs.hlsl")
      removeflags("ExcludeFromBuild")
      shadertype("Vertex")


   -- Warnings as errors
   shaderoptions({"/WX"})

The file tells premake which kind of shader is contained in each of the files. I think the keywords in here are very self-explanatory however with each filter you can specify how each shader file will be compiled. Shadertype defines what type of shader the file is containing, the shaderentry contains the name of the entry function of the shader.

Kurzmitteilung

Day 0 – Learning Game Dev

I have to admit that I lied in the headline. It’s not literally my first day of game development, of course. Actually it’s quite the contrary – I do this for alot of years now. However, there is still so much to learn for me thus it feels like day 0. This is the reason why I decided to go back to a passion project of mine and write about my journey in this blog.

A couple of years ago I started to work on my own game engine with C++ and DirectX / OpenGl. I guess that’s what a lot of people have done or still do. I never got that far since I always have been busy with work.

This is something I truly regret since I’ve a lot of interest in low-level engine design and C / C++ programming. I mean after all it’s a secret dream of mine to break into the AAA industry to work on some of these big projects. Eventhough, I have a lot of fun with what I do now, but I still have this itch to get back into game engine programming.

A while ago I finally decided to go back and pick up again where I left a year ago while reading some great articles about game engine architectures (I will post another blog post focusing on resources I use later). Since then I got DX12 up and running, learned about ImGui and got tinyobjloader integrated. However I realized that progress is really slow when using DX12 and decided to use OpenGL (for now) in order to be able to get to the advanced concepts of engine development faster instead of dealing with all the hassle that is DX12. I will most likely come back to DX12 later once I got more stuff implemented into the engine. After all the goal is to develop a small 3D game with it.

Besides working on the engine at some days I decided to dig a bit deeper into Unreal Engine 4. For the last couple of years I solely used Unity to develop games professionally or in private. At we work use Unity, too since it’s pretty straight forward and at least for smaller games quite convenient.

I stumbled over a very neat art package in the asset store of Unreal and my imagination ran wild. I decided to start a small prototype project and work on it in my spare time to make myself more familiar with Unreal and broaden my skill.

I will post regular updates of the two projects whenever I have something interesting to tell. I try to post something every day however this depends on how busy I’m with work. I might post articles about work related stuff from time to time, too.

This blog isn’t meant as some sort of tutorial series on how to write an engine or game but rather to write down my journey of me learning all the concepts and improving my skill.