2024-01-17 18:53:31 +01:00
|
|
|
|
|
|
|
|
class MakeMaterial {
|
|
|
|
|
|
2024-02-05 20:57:20 +01:00
|
|
|
static defaultScon: shader_context_t = null;
|
|
|
|
|
static defaultMcon: material_context_t = null;
|
2024-01-17 18:53:31 +01:00
|
|
|
static heightUsed = false;
|
|
|
|
|
|
|
|
|
|
static parseMeshMaterial = () => {
|
|
|
|
|
let m = Project.materialData;
|
|
|
|
|
|
2024-01-30 23:55:35 +01:00
|
|
|
for (let c of m._shader.contexts) {
|
|
|
|
|
if (c.name == "mesh") {
|
|
|
|
|
array_remove(m._shader.contexts, c);
|
|
|
|
|
array_remove(m._shader._contexts, c);
|
2024-01-26 22:09:49 +01:00
|
|
|
MakeMaterial.deleteContext(c);
|
2024-01-17 18:53:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 16:50:04 +01:00
|
|
|
let con = MakeMesh.run({ name: "Material", canvas: null });
|
2024-02-19 17:07:09 +01:00
|
|
|
let scon: shader_context_t = shader_context_create(con.data);
|
2024-02-05 20:57:20 +01:00
|
|
|
scon._override_context = {};
|
2024-01-17 18:53:31 +01:00
|
|
|
if (con.frag.sharedSamplers.length > 0) {
|
|
|
|
|
let sampler = con.frag.sharedSamplers[0];
|
2024-02-05 20:57:20 +01:00
|
|
|
scon._override_context.shared_sampler = sampler.substr(sampler.lastIndexOf(" ") + 1);
|
2024-01-17 18:53:31 +01:00
|
|
|
}
|
|
|
|
|
if (!Context.raw.textureFilter) {
|
2024-02-05 20:57:20 +01:00
|
|
|
scon._override_context.filter = "point";
|
2024-01-17 18:53:31 +01:00
|
|
|
}
|
2024-02-05 20:57:20 +01:00
|
|
|
scon._override_context.addressing = "repeat";
|
2024-01-30 23:55:35 +01:00
|
|
|
m._shader.contexts.push(scon);
|
|
|
|
|
m._shader._contexts.push(scon);
|
2024-01-17 18:53:31 +01:00
|
|
|
|
|
|
|
|
Context.raw.ddirty = 2;
|
|
|
|
|
|
|
|
|
|
///if arm_voxels
|
2024-01-26 22:09:49 +01:00
|
|
|
MakeMaterial.makeVoxel(m);
|
2024-01-17 18:53:31 +01:00
|
|
|
///end
|
|
|
|
|
|
|
|
|
|
///if (krom_direct3d12 || krom_vulkan)
|
|
|
|
|
RenderPathRaytrace.dirty = 1;
|
|
|
|
|
///end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///if arm_voxels
|
2024-02-05 20:57:20 +01:00
|
|
|
static makeVoxel = (m: material_data_t) => {
|
2024-01-17 18:53:31 +01:00
|
|
|
let rebuild = true; // heightUsed;
|
|
|
|
|
if (Config.raw.rp_gi != false && rebuild) {
|
2024-02-05 20:57:20 +01:00
|
|
|
let scon: shader_context_t = null;
|
2024-01-30 23:55:35 +01:00
|
|
|
for (let c of m._shader._contexts) {
|
|
|
|
|
if (c.name == "voxel") {
|
2024-01-17 18:53:31 +01:00
|
|
|
scon = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (scon != null) MakeVoxel.run(scon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
///end
|
|
|
|
|
|
|
|
|
|
static parsePaintMaterial = () => {
|
|
|
|
|
let m = Project.materialData;
|
2024-02-05 20:57:20 +01:00
|
|
|
let scon: shader_context_t = null;
|
|
|
|
|
let mcon: material_context_t = null;
|
2024-01-30 23:55:35 +01:00
|
|
|
for (let c of m._shader.contexts) {
|
|
|
|
|
if (c.name == "paint") {
|
|
|
|
|
array_remove(m._shader.contexts, c);
|
|
|
|
|
array_remove(m._shader._contexts, c);
|
2024-01-26 22:09:49 +01:00
|
|
|
if (c != MakeMaterial.defaultScon) MakeMaterial.deleteContext(c);
|
2024-01-17 18:53:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (let c of m.contexts) {
|
2024-01-30 23:55:35 +01:00
|
|
|
if (c.name == "paint") {
|
2024-01-26 22:09:49 +01:00
|
|
|
array_remove(m.contexts, c);
|
2024-01-30 23:55:35 +01:00
|
|
|
array_remove(m._contexts, c);
|
2024-01-17 18:53:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 16:50:04 +01:00
|
|
|
let sdata: TMaterial = { name: "Material", canvas: null };
|
2024-02-05 20:57:20 +01:00
|
|
|
let mcon2: material_context_t = { name: "paint", bind_textures: [] };
|
2024-01-26 22:09:49 +01:00
|
|
|
let con = MakePaint.run(sdata, mcon2);
|
2024-01-17 18:53:31 +01:00
|
|
|
|
|
|
|
|
let compileError = false;
|
2024-02-05 20:57:20 +01:00
|
|
|
let scon2: shader_context_t;
|
2024-02-19 17:07:09 +01:00
|
|
|
let _scon: shader_context_t = shader_context_create(con.data);
|
|
|
|
|
if (_scon == null) compileError = true;
|
|
|
|
|
scon2 = _scon;
|
|
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
if (compileError) return;
|
2024-02-05 20:57:20 +01:00
|
|
|
scon2._override_context = {};
|
|
|
|
|
scon2._override_context.addressing = "repeat";
|
2024-02-19 17:07:09 +01:00
|
|
|
let mcon3: material_context_t = material_context_create(mcon2);
|
2024-01-17 18:53:31 +01:00
|
|
|
|
2024-01-30 23:55:35 +01:00
|
|
|
m._shader.contexts.push(scon2);
|
|
|
|
|
m._shader._contexts.push(scon2);
|
2024-01-26 22:09:49 +01:00
|
|
|
m.contexts.push(mcon3);
|
2024-01-30 23:55:35 +01:00
|
|
|
m._contexts.push(mcon3);
|
2024-01-17 18:53:31 +01:00
|
|
|
|
2024-01-26 22:09:49 +01:00
|
|
|
if (MakeMaterial.defaultScon == null) MakeMaterial.defaultScon = scon2;
|
|
|
|
|
if (MakeMaterial.defaultMcon == null) MakeMaterial.defaultMcon = mcon3;
|
2024-01-17 18:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDisplaceStrength = (): f32 => {
|
2024-01-31 15:12:28 +01:00
|
|
|
let sc = Context.mainObject().base.transform.scale.x;
|
2024-01-17 18:53:31 +01:00
|
|
|
return Config.raw.displace_strength * 0.02 * sc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static voxelgiHalfExtents = (): string => {
|
|
|
|
|
let ext = Context.raw.vxaoExt;
|
|
|
|
|
return `const vec3 voxelgiHalfExtents = vec3(${ext}, ${ext}, ${ext});`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 20:57:20 +01:00
|
|
|
static deleteContext = (c: shader_context_t) => {
|
2024-01-17 18:53:31 +01:00
|
|
|
Base.notifyOnNextFrame(() => { // Ensure pipeline is no longer in use
|
2024-02-05 20:57:20 +01:00
|
|
|
shader_context_delete(c);
|
2024-01-17 18:53:31 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|