Closed yyc-git closed 4 years ago
The included glsl compiler doesn't handle includes, it's up to the application. You have to recursively lookup the content of the included file and inline it. This is how I do it in my projects - see here.
Alternatively you can use the nvk-essentials package which contains a GLSL compiler and support for includes.
Thanks for your reply!!!
Yes, I can use "include" by import your "loadShaderFile"(created from your project). But it has a little bug: inliner.mjs
import fs from "fs";
//should add this line!
import path from "path";
...
So the complete code to support include is: index.mjs
//should move inliner.mjs to my project
import { loadShaderFile } from "./inliner.mjs";
...
// rasterization shaders
let vertexShaderModule = device.createShaderModule({
code: loadShaderFile(`${baseShaderPath}/screen.vert`)
});
let fragmentShaderModule = device.createShaderModule({
code: loadShaderFile(`${baseShaderPath}/screen.frag`)
});
// ray-tracing shaders
let rayGenShaderModule = device.createShaderModule({
code: loadShaderFile(`${baseShaderPath}/ray-generation.rgen`)
});
let rayCHitShaderModule = device.createShaderModule({
code: loadShaderFile(`${baseShaderPath}/ray-closest-hit.rchit`)
});
let rayMissShaderModule = device.createShaderModule({
code: loadShaderFile(`${baseShaderPath}/ray-miss.rmiss`)
});
ray-closest-hit.rchit
#version 460
...
#extension GL_GOOGLE_include_directive : enable
#pragma shader_stage(closest)
#include "wavefront.glsl"
wavefront.glsl
//define the export code like:
struct Data1
{
float objId;
};
int getData2(){
return 1;
}
Hello @maierfelix ! my code is: rchit glsl:
wavefront.glsl:
when run the code, it error:
How to include glsl??? Thanks very much!!!