TerraForge3D  2.3.1
3D Terrain And Landscape Generator
BakeToSlotNode.cpp
1#include "Shading/ShaderNodes/BakeToSlotNode.h"
2
3#include <iostream>
4
5void BakeToSlotNode::OnEvaluate(GLSLFunction *function, GLSLLine *line)
6{
7 if(inputPins[0]->IsLinked())
8 {
9 GLSLLine tmp("", "");
10 inputPins[0]->other->Evaluate(GetParams(function, &tmp));
11 function->AddLine(GLSLLine("textureBakeSlots[int(" + SDATA(0) + ")] = " + tmp.line + ";"));
12 line->line = tmp.line;
13 }
14 else
15 {
16 function->AddLine(GLSLLine("textureBakeSlots[int(" + SDATA(0) + ")] = vec3(0.0f);"));
17 line->line = "vec3(0.0f)";
18 }
19}
20
21void BakeToSlotNode::Load(nlohmann::json data)
22{
23 slot = data["slot"];
24}
25
26nlohmann::json BakeToSlotNode::Save()
27{
28 nlohmann::json data;
29 data["type"] = "BakeToSlot";
30 data["slot"] = slot;
31 return data;
32}
33
34void BakeToSlotNode::UpdateShaders()
35{
36 sharedData->d0 = static_cast<float>(slot);
37}
38
39void BakeToSlotNode::OnRender()
40{
41 DrawHeader("Bake to Slot");
42 ImGui::PushItemWidth(100);
43
44 ImGui::NewLine();
45 inputPins[0]->Render();
46
47 if(ImGui::InputInt("Slot", &slot))
48 {
49 sharedData->d0 = static_cast<float>(slot);
50 }
51
52 outputPins[0]->Render();
53
54 if(slot == 0)
55 {
56 ImGui::TextColored(ImVec4(7.0f, 0.0, 0.0f, 1.0f), "Slot 0 is reserved for Height Map!");
57 }
58
59 if(slot < 0 || slot > 10)
60 {
61 slot = 1;
62 }
63
64 ImGui::PopItemWidth();
65}
66
67BakeToSlotNode::BakeToSlotNode(GLSLHandler *handler)
68 :SNENode(handler)
69{
70 name = "Bake To Slot";
71 slot = 1;
72 headerColor = ImColor(SHADER_VALUE_NODE_COLOR);
73 outputPins.push_back(new SNEPin(NodeEditorPinType::Output, SNEPinType::SNEPinType_Float3));
74 inputPins.push_back(new SNEPin(NodeEditorPinType::Input, SNEPinType::SNEPinType_Float3));
75}
76
77
78BakeToSlotNode::~BakeToSlotNode()
79{
80}
a class to store JSON values
Definition: json.hpp:17860