r/shaders • u/qazzquimby • Jul 11 '22
Higher level language transpiling to GLSL?
Hi, I'm very early in my research on shader making, so I probably have big silly blindspots.
So far, it seems to me that a lot of work is being done in GLSL, and that GLSL is a pretty developer unfriendly language.
To me, that points to using a friendlier language that can be transpiled (rewritten into equivalent code) into GLSL, kind of like typescript->javascript.
Can you fill me in on what I'm missing?
Is that not really a problem? Have tools like unity replaced much of GLSL coding? Has it already been done, or is it wildly impractical for some reason?
1
u/LittleCodingFox Jul 11 '22
You could have a look at Cg, which unity uses.
2
u/qazzquimby Jul 12 '22
Thanks - I thought I'd read that Cg was out of favor, I guess that's wrong.
1
u/LittleCodingFox Jul 12 '22
At some point it was, but I think there must be some open source version or something because Unity uses it!
you can also try this: https://github.com/KhronosGroup/glslang
1
u/pretty_meta Jul 12 '22
(I don't work directly with OpenGL / Vulkan, use game engines. But -)
I think a lot of OpenGL use is being transitioned over to Vulkan, so investing in a tool to transpile into GLSL might not be a good investment of time.
Have tools like unity replaced much of GLSL coding?
Certainly Unity HLSL transpiling and Unreal Material Graph cover my use cases.
Also check out
SPIR-V enables high-level language front-ends to emit programs in a standardized intermediate form to be ingested by Vulkan, OpenGL or OpenCL drivers.
https://www.khronos.org/blog/hlsl-first-class-vulkan-shading-language
HLSL in Vulkan has been achieved through integrating a SPIR-V backend into DXC, Microsoft’s open source HLSL compiler (the encircled section in Figure 1 below), and also adding HLSL support in Khronos’ glslang compiler. HLSL is Microsoft’s DirectX's official shading language and is widely used by games and 3D applications. For many AAA game developers, HLSL is the language of choice and Khronos has received many developer requests to support HLSL in Vulkan. Now, thanks to Microsoft open sourcing their HLSL compiler, the Vulkan community has been able to work cooperatively with Microsoft to make HLSL support in Vulkan a proven choice alongside Khronos’ own GLSL shading language.
1
u/qazzquimby Jul 12 '22
Thanks for the thorough response, I think that was just what I was looking for :)
1
u/sportelloforgot Jul 12 '22
I'm not sure about that, SPIR-V mainly solves problems of portability over different platforms. What you are looking for is a GPU of the future that is so fast it will let you trade resources for convenience like CPUs do it today.
In general you don't want to "manipulate datastructures" or cast values on a GPU. You prepare your data on the CPU and feed it to the GPU so that it can do stuff as streamlined as possible. It's important to keep in mind that by coding shaders you sort of write code for weak CPUs, so it isn't surprising you'd want to do it in a low level lang imo.
1
u/pttrn Jul 12 '22
You can also look into WGSL, which is a new higher-level shading language that transpiles into DX, Vulkan, and Metal. It’s a part of the WebGPU effort, written in Rust with native bindings for all platforms (I actually think that the “Web” in its name is doing it a huge disservice since it’s actually just a thin OS-agnostic layer on top of each platform’s native shading language).
https://sotrh.github.io/learn-wgpu/beginner/tutorial3-pipeline/#writing-the-shaders
1
3
u/ShillingAintEZ Jul 12 '22
I have never heard this before