shader path can be relative to material

This commit is contained in:
Mikulas Florek 2022-12-03 20:55:17 +01:00
parent 967510d4e0
commit 2db8106c6e
36 changed files with 60 additions and 37 deletions

View file

@ -1,3 +1,3 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,3 +1,3 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture ""
texture ""

View file

@ -1,3 +1,3 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture "/editor/models/icon.tga"

View file

@ -1,2 +1,2 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture "/editor/models/phy_box_icon.tga"

View file

@ -1,2 +1,2 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture "/editor/models/phy_controller_icon.tga"

View file

@ -1,2 +1,2 @@
shader "pipelines/editor_icon.shd"
shader "/pipelines/editor_icon.shd"
texture "/editor/models/terrain_icon.tga"

View file

@ -1,4 +1,4 @@
shader "pipelines/world_grid.shd"
shader "/pipelines/world_grid.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
emission(0.000000)

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(false)
layer "default"
emission(0.000000)

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
emission(0.000000)

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
texture ""
texture ""
texture ""

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/standard.shd"
shader "/pipelines/standard.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/particles.shd"
shader "/pipelines/particles.shd"
backface_culling(true)
layer "default"
defines {}

View file

@ -1,4 +1,4 @@
shader "pipelines/decal.shd"
shader "/pipelines/decal.shd"
backface_culling(true)
layer "decal"
defines {}

View file

@ -217,6 +217,10 @@ bool Path::hasExtension(const char* filename, const char* ext)
return equalIStrings(tmp, ext);
}
Path::operator Span<const char>() const {
return Span(m_path, stringLength(m_path));
}
PathInfo::PathInfo(const char* path) {
char tmp[LUMIX_MAX_PATH];
Path::normalize(path, Span(tmp));

View file

@ -41,6 +41,7 @@ struct LUMIX_ENGINE_API Path {
const char* c_str() const { return m_path; }
bool isEmpty() const { return m_path[0] == '\0'; }
static u32 capacity() { return LUMIX_MAX_PATH; }
operator Span<const char>() const;
private:
char m_path[LUMIX_MAX_PATH];

View file

@ -1250,7 +1250,7 @@ void FBXImporter::writeMaterials(const char* src, const ImportConfig& cfg)
}
out_file.clear();
writeString("shader \"pipelines/standard.shd\"\n");
writeString("shader \"/pipelines/standard.shd\"\n");
if (material.alpha_cutout) writeString("defines {\"ALPHA_CUTOUT\"}\n");
if (material.textures[2].is_valid) writeString("metallic(1.000000)");

View file

@ -1,4 +1,5 @@
#include "renderer/material.h"
#include "engine/engine.h"
#include "engine/file_system.h"
#include "engine/hash.h"
#include "engine/log.h"
@ -144,7 +145,13 @@ bool Material::save(IOutputStream& file)
if(!isReady()) return false;
if(!m_shader) return false;
file << "shader \"" << m_shader->getPath().c_str() << "\"\n";
Span<const char> mat_dir = Path::getDir(getPath().c_str());
if (startsWith(m_shader->getPath(), mat_dir)) {
file << "shader \"" << Span<const char>(m_shader->getPath()).fromLeft(mat_dir.length()) << "\"\n";
}
else {
file << "shader \"/" << m_shader->getPath().c_str() << "\"\n";
}
file << "backface_culling(" << (isBackfaceCulling() ? "true" : "false") << ")\n";
file << "layer \"" << m_renderer.getLayerName(m_layer) << "\"\n";
@ -162,8 +169,7 @@ bool Material::save(IOutputStream& file)
for (u32 i = 0; i < m_texture_count; ++i) {
char path[LUMIX_MAX_PATH];
if (m_textures[i] && m_textures[i] != m_shader->m_texture_slots[i].default_texture) {
Span<const char> texture_path(m_textures[i]->getPath().c_str(), m_textures[i]->getPath().length());
Span<const char> mat_dir = Path::getDir(getPath().c_str());
Span<const char> texture_path(m_textures[i]->getPath());
if (startsWith(texture_path, mat_dir)) {
copyString(Span(path), Span(texture_path).fromLeft(mat_dir.length()));
}
@ -599,7 +605,19 @@ int shader(lua_State* L)
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Material* material = (Material*)lua_touserdata(L, -1);
lua_pop(L, 1);
material->setShader(Path(path));
if (!path[0]) material->setShader(nullptr);
else {
char c = path[0];
if (c != '\\' && c != '/') {
Span <const char> material_dir = Path::getDir(material->getPath().c_str());
StaticString<LUMIX_MAX_PATH> fullpath(material_dir, path);
material->setShader(Path(fullpath));
}
else {
material->setShader(Path(path));
}
}
return 0;
}