bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Shader defs can now have a value

Open mockersf opened this issue 3 years ago • 1 comments
trafficstars

Objective

  • shaders defs can now have a bool or int value
  • #if SHADER_DEF <operator> 3
    • ok if SHADER_DEF is defined, has the correct type and pass the comparison
    • ==, !=, >=, >, <, <= supported
  • #SHADER_DEF or #{SHADER_DEF}
    • will be replaced by the value in the shader code

Migration Guide

  • replace shader_defs.push(String::from("NAME")); by shader_defs.push(String::from("NAME").into());
  • if you used shader def NO_STORAGE_BUFFERS_SUPPORT, check how AVAILABLE_STORAGE_BUFFER_BINDINGS is now used in Bevy default shaders

mockersf avatar Sep 07 '22 00:09 mockersf

How will this feature be documented ? As the syntax is proper to bevy, even though resembling what's existing in other solutions, I think documentation and discoverability will be very important :)

Examples and Bevy book.

If this get merged, I'll continue on adding features to shader defs, the two I have planned is being able to define a shader def from inside a shader, and being able to have a function as a shader def. They will both be somewhat more complicated, so I'll do it small PR by small PR. But they will also have a lot more added value and it will be quite easier to show how this can be used.

mockersf avatar Sep 09 '22 19:09 mockersf

Very nice work! I love the changes / they resolved all of my comments.

cart avatar Nov 21 '22 22:11 cart

bors r+

cart avatar Nov 21 '22 22:11 cart

Build failed:

bors[bot] avatar Nov 21 '22 22:11 bors[bot]

bors retry

cart avatar Nov 21 '22 22:11 cart