r/shaders • • 7d ago

How do I write shaders in python

Hello Everyone, I hope you all are doing well.
So, even though I have been writing python programs for a while. I want to learn to write shaders for visual effects, filters, 3d morphs and also ray tracing, where do I start? Can you mention resources or any work you have done before and would like to share

1 Upvotes

6 comments sorted by

3

u/J_Liljedahl 7d ago

Shaders are written in special shader languages, like GLSL, MSL, HLSL. I'm not aware of any Python-based shader language or compiler. I think a good place to start is The Book of Shaders: https://thebookofshaders.com

1

u/Big_Award_4491 7d ago

I don’t think you can. Shaders use their own language that is different depending on which shader model you use (DirectX, Vulkan, Metal etc).

1

u/Undeniable_Dilemma_ 7d ago

Why do you want to write shaders if you don't even know what they are?

Shaders are the code that gets executed on the GPU. Inner workings of the GPU are not out in the open, so you have to talk to it through some graphics API, like OpenGL or Vulkan.

Only SOME parts of the rendering pipeline are programmable, so you can write what we call a shader, and send it to the GPU to be executed at a certain stage of the rendering pipeline. Those shaders require to be written in a specific language, like GLSL for example.

You can read more about it on learnopengl.com

1

u/TwitchyWizard 7d ago edited 6d ago

I would start with the book of shaders ( https://thebookofshaders.com/ ) and shader toy ( https://www.shadertoy.com/ ). Or just writing shaders in Unity with Youtube tutorials to get you started. You don't write shaders in python but in languages like HLSL, GLSL and they are so similar that if you can one you can the other one. There is also Slang but I know very little about it. DirectX, Metal and Vulkan are graphics APIs that are good to read up on.

1

u/Mroz_Game 1d ago

If you need hardware accelerated ray tracing, you’re left with Vulkan / DX12 / Metal

You can call some of these apis through bindings from python but it kinda sucks as they are not cross platform.

And the shaders will not be in python, I think you have a misconception about what a shader is or what python is.