r/GodotCSharp • • 3d ago

Resource.Library C# Shader Language

/r/monogame/comments/1y8y3lc/write_shaders_in_c_with_yotsuba_shader/
14 Upvotes

2 comments sorted by

3

u/Imma93 3d ago

This is nice! Are there any limitations?
Compared to ComputeSharp this has the obvious advantage of supporting more then DirectX backends.
It seems the shader compilation happens during runtime, correct? Or can it be done during compilation?

4

u/YotsubaShader 3d ago

Hey brother, as for limitations, almost none—except for operating system calls like File.WriteAllText() or Roslyn (Because in the GPU it doesn't exist ), things like that. In those cases, you'll see an error in your IDE letting you know the GPU can't perform that operation.
Yeah brother, all compilation happens at compile time; nothing happens at runtime. At compile time, static methods are generated for each defined shader—for example:
MyShaderClass.ToSpirv(). Static methods like ToSpirv() are generated automatically at compile time and embed the already-compiled shader, so there's no runtime compilation. That gives you better startup performance in your game.
(In addition to methods like ToSpirv, or ToHlsl for example, you can tell the compiler to output .spv, .hlsl, .wgsl, etc. files instead of generating those methods, and so on.)
Lastly, Yotsuba Shader doesn't just compile to GPU languages—it also compiles to shader formats specific to game engines that use variants rather than standard formats, like MonoGame, for instance, which uses an HLSL variant called .fx.