Skip to content

Commit

Permalink
Fix for ticket #71
Browse files Browse the repository at this point in the history
  • Loading branch information
dparnell committed Feb 12, 2024
1 parent 9225568 commit 8316da8
Show file tree
Hide file tree
Showing 8 changed files with 1,086 additions and 994 deletions.
51 changes: 51 additions & 0 deletions examples/ticket_71.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// see https://github.com/bevyengine/bevy/blob/c1a4e29a1ec2b3a54fa0449ed28bb59ec00ac1ed/crates/bevy_pbr/src/render/pbr.wgsl

#import bevy_pbr::{
pbr_functions::alpha_discard,
pbr_fragment::pbr_input_from_standard_material,
}

#ifdef PREPASS_PIPELINE
#import bevy_pbr::{
prepass_io::{VertexOutput, FragmentOutput},
pbr_deferred_functions::deferred_output,
}
#else
#import bevy_pbr::{
forward_io::{VertexOutput, FragmentOutput},
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT,
}
#endif

@fragment
fn fragment(
in: VertexOutput,
@builtin(front_facing) is_front: bool,
) -> FragmentOutput {
// generate a PbrInput struct from the StandardMaterial bindings
var pbr_input = pbr_input_from_standard_material(in, is_front);

// alpha discard
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);

#ifdef PREPASS_PIPELINE
// write the gbuffer, lighting pass id, and optionally normal and motion_vector textures
let out = deferred_output(in, pbr_input);
#else
// in forward mode, we calculate the lit color immediately, and then apply some post-lighting effects here.
// in deferred mode the lit color and these effects will be calculated in the deferred lighting shader
var out: FragmentOutput;
if (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {
out.color = apply_pbr_lighting(pbr_input);
} else {
out.color = pbr_input.material.base_color;
}

// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
// note this does not include fullscreen postprocessing effects like bloom.
out.color = main_pass_post_lighting_processing(pbr_input, out.color);
#endif

return out;
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = wgslplugin
pluginName = wgsl
# SemVer format -> https://semver.org
pluginVersion = 0.0.29
pluginVersion = 0.0.30

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand All @@ -13,7 +13,7 @@ pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
platformVersion = 2022.3
platformVersion = 2023.2

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
1,998 changes: 1,014 additions & 984 deletions src/main/gen/wgslplugin/language/_WgslLexer.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/gen/wgslplugin/language/parser/WgslParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/gen/wgslplugin/language/psi/WGSLIfStatement.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/main/java/wgslplugin/language/WGSLLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import static wgslplugin.language.psi.WGSLTypes.*;
%state TYPE_SPEC
%state BIND_SPEC
%state ATTRIBUTE
%state PREPROCESSOR
%state PREPROCESSOR_NESTED

// note: newlines are parsed separately to allow leading whitespace on a preprocessor declaration line
WHITE_SPACE=[^\S\r\n]+
Expand All @@ -58,13 +60,13 @@ INT_LITERAL = -?0x[0-9a-fA-F]+|0|-?[1-9][0-9]*
UINT_LITERAL = 0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u
DECIMAL_FLOAT_LITERAL = ((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)
HEX_FLOAT_LITERAL = -?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))
PREPROCESSOR_DECLARATION = "#"[^\r\n]*
PREPROCESSOR_DECLARATION = "#"[^\r\n\{\[]+

IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)

%%

<YYINITIAL> ^\s*{PREPROCESSOR_DECLARATION} { return PREPROCESSOR_DECLARATION; }
<YYINITIAL> ^\s*{PREPROCESSOR_DECLARATION} { pushState(PREPROCESSOR); return PREPROCESSOR_DECLARATION; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC, ATTRIBUTE> {WHITE_SPACE} { return WHITE_SPACE; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC, ATTRIBUTE> {NEWLINE} { return WHITE_SPACE; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC, ATTRIBUTE> {LINE_COMMENT} { return LINE_COMMENT; }
Expand Down Expand Up @@ -92,6 +94,15 @@ IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)
<YYINITIAL> ";" { return SEMICOLON; }
<YYINITIAL> "@" { return AT; }

<PREPROCESSOR, PREPROCESSOR_NESTED> "{" { pushState(PREPROCESSOR_NESTED); return PREPROCESSOR_DECLARATION; }
<PREPROCESSOR, PREPROCESSOR_NESTED> "}" { popState(); return PREPROCESSOR_DECLARATION; }

<PREPROCESSOR, PREPROCESSOR_NESTED> "[" { pushState(PREPROCESSOR); return PREPROCESSOR_DECLARATION; }
<PREPROCESSOR, PREPROCESSOR_NESTED> "]" { popState(); return PREPROCESSOR_DECLARATION; }
<PREPROCESSOR> {NEWLINE} { popState(); return WHITE_SPACE; }
<PREPROCESSOR_NESTED> {NEWLINE} { return WHITE_SPACE; }
<PREPROCESSOR, PREPROCESSOR_NESTED> .+ { return PREPROCESSOR_DECLARATION; }

<TYPE_SPEC> "function" { return FUNCTION; }
<TYPE_SPEC> "private" { return PRIVATE; }
<TYPE_SPEC> "workgroup" { return WORKGROUP; }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wgslplugin/language/wgsl.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ assignment_statement ::=
| UNDERSCORE EQUAL expression

if_statement ::=
IF paren_expression compound_statement ( ELSE else_statement )?
IF expression compound_statement ( ELSE else_statement )?

else_statement ::=
compound_statement
Expand Down

0 comments on commit 8316da8

Please sign in to comment.