Skip to content

Commit 4d7ef8b

Browse files
authored
fix(import): fallback to the default shader when the input's link is missing
Fix loading issue for https://www.shadertoy.com/view/MlsfR4.
1 parent bfad07e commit 4d7ef8b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

shadertoy/NodeEditor/PipelineEditor.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ static constexpr auto initialShader = R"(void mainImage( out vec4 fragColor, in
7979
}
8080
)";
8181

82+
static constexpr auto initialCubeMap = R"(void mainCubemap( out vec4 fragColor, in vec2 fragCoord, in vec3 rayOri, in vec3 rayDir )
83+
{
84+
// Ray direction as color
85+
vec3 col = 0.5 + 0.5*rayDir;
86+
87+
// Output to cubemap
88+
fragColor = vec4(col,1.0);
89+
}
90+
)";
91+
92+
static constexpr auto initialBuffer = R"(void mainImage( out vec4 fragColor, in vec2 fragCoord )
93+
{
94+
fragColor = vec4(0.0,0.0,1.0,1.0);
95+
}
96+
)";
97+
8298
uint32_t PipelineEditor::nextId() {
8399
return mNextId++;
84100
}
@@ -1651,7 +1667,16 @@ void PipelineEditor::loadFromShaderToy(const std::string& path) {
16511667
}
16521668

16531669
auto channel = input.at("channel").get<uint32_t>();
1654-
auto src = newShaderNodes.at(input.at("id").get<std::string>());
1670+
auto inputId = input.at("id").get<std::string>();
1671+
if(!newShaderNodes.count(inputId)) {
1672+
// Shadertoy doesn't fail when an input is missing, so we create a default dummy node
1673+
auto& inputNode = spawnShader(inputType != "cubemap" ? NodeType::Image : NodeType::CubeMap);
1674+
inputNode.editor.setText(common + (inputType == "cubemap" ? initialCubeMap : initialBuffer));
1675+
inputNode.name = inputId;
1676+
newShaderNodes.emplace(inputId, &inputNode);
1677+
}
1678+
1679+
auto src = newShaderNodes.at(inputId);
16551680
const auto idxSrc = getOrder(src->name);
16561681
if(idxSrc < idxDst) {
16571682
addLink(src, node, channel, &input);

0 commit comments

Comments
 (0)