ThreeJS - Shaders in Separate Files (with syntax highlighting)

preview_player
Показать описание
When you're working with ThreeJS you're going to come across shaders. These use a language called WebGL, OpenGL, or glsl, all of which are actually the correct name for this initially confusing language.

On of the big challenges for me starting off was the you had to have glsl code in strings, losing syntax highlighting, or in .glsl files, which needed complicated build steps.

Here I describe a more straight forward way of storing WebGL in separate files, with syntax highlighting, and compatible with regular JavaScript imports.

Рекомендации по теме
Комментарии
Автор

Thanks man, I had this problem and could not find a solution anywhere.

diviik
Автор

Put a /* glsl */ comment after the equals sign in your multi-line string literal. Export that literal as default in a separate file, import it into a variable. Watch from 8:00 to save time.

omgnowairly
Автор

Awesome resource, to have out there. I would have loved to find this last year when I was getting started learning glsl cause I pulled my hair out figuring it out. I do this string method usually in the same file for rapid prototyping but have been enjoying using parcel bundler with glslify to include .glsl files that i can lint as a separate glsl file using import from syntax in the header. The only issue is using shader material the linter thinks some things are missing because of what goes on behind the scenes in three.us to create a shader material so I usually disable the validator. One Love, !

gschian-
Автор

Just found your channel. Thanks for the tutorial

derciojds
Автор

Instead of using doing this you can get the webGL glsl extension for the highlighting then npm install the glsl plugin so that you can import .glsl files

mohib
Автор

Good god thank you. Highlighting's weak, but hell, at least it's better than just orange

franciscomagalhaes
visit shbcf.ru