-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace temporary .gdshader
syntax with more extensive support
#360
Conversation
The shader language in 4.0 is mostly the same as 3.x, except there are a few new keywords such as |
Awesome, I'll have this stuff double-checked sometime today. |
I'm no expert in any of this, but according to this article, there is a It also has implications on how it should recognize these identifier tokens. The ideal would be semantic highlighting, but without that implemented, the best it can do is to assume PascalCase refers to structs. This is similar to what I'm currently doing, assuming any ALL_UPPERCASE identifier (such as TIME, ALBEDO, PI, etc) refers to a language variable (in the latter case they could be listed too, I admit I didn't do it out of laziness). I think it's reasonable to assume this until actual semantic parsing is implemented/enabled. These should be colored similar to language types like It's also possible that I don't have to make such assumptions; so maybe a struct identifier can be recognized depending on where it appears. This would be the ideal way to detect them without needing semantic highlighting. It's important to categorize these tokens right so that they look right regardless of theme, so maybe I'll take a look at this today. |
4.0 indeed supports |
Thanks for the link, I added some snippets from the article to the example file.
This is what I would do, with the caveat that I have no idea if there's some kind of normal convention for shaders that uses PascalCase for something other than a struct "type". |
I think the dilemma is more about assuming all |
Taking a superficial look at the example, it seems it should be absolutely possible to mark struct identifiers properly in most places without assuming naming conventions. The only place where it's an issue is constructors, which, without a |
Here's some specific behavior I found when making tests with gdshader (Godot 4.0.alpha8). It's worth noting that hints are indeed reserved words (and shader types | render modes aren't). shader_type spatial;
render_mode wireframe;
const uint one = 1u;
void fn() {}
struct A { int b; };
struct MyStruct { // only uninitialized fields are allowed
lowp int x; // only precision modifiers allowed
A[1] s; A t[one]; // and arrays
};
void vertex() {
//err: int hint_white = 0; // hints are reserved words, just like other keywords
int ALBEDO = 0, xx = ALBEDO; // language variables are only reserved in their function
}
// fragment|light are not reserved functions in particle shaders, so params are allowed in this case
void fragment() {
int spatial = 0, xx1 = spatial; // shader types are not reserved words
int wireframe = 0, xx2 = wireframe; // render modes are not reserved words
int fragment = 0, fn = 0, xx3 = fragment; // can declare locals using existing function names
int MyStruct = 0, xx4 = MyStruct; // can declare locals using existing struct names
float a = 0.f, b = 0.e0; // f|e can appear right after . so weird field-like syntax is valid
A[one] x1 = { A(0) }; // a positive const identifier is allowed as array size
A[1u] x2 = { A(0) }; // unsigned int|uint literals are also allowed (but not expr)
A x3[] = { A(0) }; // [] may appear in right side, with same rules
}
const MyStruct[1] x = { MyStruct(0, {A(0)}, {A(0)}) }; Lastly, weird cases like |
This is fixed in 4.0 (see godotengine/godot#55623)
This is allowed GLSL syntax and would not be changed in order to preserve compatibility. |
Ah, I see. So the weird definition came from GLSL. Makes sense. I'm not sure what version of GLSL it's based on, but I checked the grammar in the spec for GLSL ES 3.0.
I meant my vscode syntax didn't support it yet. I didn't know it wasn't in Godot 3, probably that's why I didn't notice it. I just noticed something else too which could be a bug (Godot 4.0.alpha8). |
This is a bug, indeed, could you post it to bug tracker? |
@Chaosus I posted in godot repo, don't know if it's the right one. |
I also updated the Array constructors Most things, such as struct identifiers, functions, field access, etc are only recognized as such when context is in the same line. MyStruct fn() { a.b // ok
// not:
MyStruct
fn
() { a.
b I might maybe try to improve this eventually, but other than such edge cases, syntax should be functional. This file with various pieces taken from docs might be useful as a starting point for testing syntax: godot4docs.gdshader.txt I lost my other test file (I think Godot automatically saved it without asking when closing ...) |
@AlfishSoftware I'll pull that update over when I have time. Thanks for digging into the details here. |
Just a note: Since I've published my extension, I had to change language id and scopeName so it doesn't clash with this extension (so both can be used, otherwise the temporary grammar is taking priority). When pulling from the grammar, make sure to change scopeName |
Of course. I had made a couple of changes to make the metadata fit the rest of our extension anyways. Thanks again for all your work on this! |
It seems Godot editor is compatible with LSP for GDScript, right? |
The LSP is currently only for GDScript, not other languages. There are no plans to add LSP support for other languages, although it may happen if a motivated contributor does the required work. I assume the language server would still run on the same host and port for this. |
OK, then. Thanks for the quick answer! |
What information would you actually get from a language server that you can't just as easily figure out in a client-only implementation? The current Godot version is the only thing I can think of. I don't think a GDShader language server makes any sense, personally. Is it even possible for a single shader to be in more than one file? |
See detailed answer in the discussion linked above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a ton!
.gdshader
syntax with more extensive support
Just to confirm, this hasn't been done, right? |
I asked because it seems tmLanguage is missing the Godot 4 keywords and type hints from my latest update, including struct syntax. |
Correct. I got a new job last month and it's been taking up 100% of my bandwidth. Thank you for checking in on this, I appreciate the reminder. @Calinou There are some additional changes I need to pull in from @AlfishSoftware's work that, quite frankly, I forgot about until now. I'll open another PR to pull in the rest of the features. |
Thanks to a generous contribution from @AlfishSoftware, we have a brand new, custom built gdshader syntax.
@Calinou Are you aware of any changes in the gdshader language from Godot3 to Godot4 that might cause a problem here? I have to admit I've barely touched shaders in Godot3, and I have absolutely no idea what's been added or removed in 4.
The following screenshots show the before/after comparison, as well as a shader embedded in a resource file: