首页 > 解决方案 > 当通过“include_str!”包含游戏时,着色器会导致游戏崩溃。(贝维)

问题描述

我从https://github.com/bevyengine/bevy/blob/main/examples/shader/shader_custom_material.rs复制粘贴了着色器示例,效果很好。但是,我想将着色器放在它们自己的文件中,因此我不需要将它们内联在 rust 脚本中。

我尝试使用include_str!将着色器文件包含为字符串,我认为这与在原始字符串文字中包含着色器相同,但是现在运行游戏时会发生此错误:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: 
Compilation("glslang_shader_preprocess:\nInfo log:\nERROR: #version: ES shaders for SPIR-V require 
version 310 or higher\nERROR: 0:1: '#' : preprocessor directive cannot be preceded by another token 
\nERROR: 2 compilation errors.  No code generated.\n\n\nDebug log:\n\n")', 
C:\Users\teevik\.cargo\registry\src\github.com-1ecc6299db9ec823\bevy_render- 
0.5.0\src\pipeline\pipeline_compiler.rs:161:22

我正在使用 bevy 0.5,所有代码都在https://gist.github.com/teevik/e7f419231a529e777d20ace06cac80b7

标签: rustbevy

解决方案


推荐阅读