TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ Evaluate()

NodeOutput TextureNode::Evaluate ( NodeInputParam  input,
NodeEditorPin pin 
)
virtual

Implements NodeEditorNode.

Definition at line 21 of file TextureNode.cpp.

22{
23 if (isDefault)
24 return NodeOutput({0.0f});
25 float res, sc, x, y;
26 res = sc = x = y = 0.0f;
27 int channel = 0;
28
29 if (pin->id == outputPins[0]->id)
30 {
31 channel = 0;
32 }
33
34 else if (pin->id == outputPins[1]->id)
35 {
36 channel = 1;
37 }
38
39 else if (pin->id == outputPins[2]->id)
40 {
41 channel = 2;
42 }
43
44 if (inputPins[0]->IsLinked())
45 {
46 x = inputPins[0]->other->Evaluate(input).value;
47 }
48
49 else
50 {
51 x = input.texX;
52 }
53
54 if (inputPins[1]->IsLinked())
55 {
56 y = inputPins[1]->other->Evaluate(input).value;
57 }
58
59 else
60 {
61 y = input.texY;
62 }
63
64 if (inputPins[2]->IsLinked())
65 {
66 sc = inputPins[2]->other->Evaluate(input).value;
67 }
68
69 else
70 {
71 sc = scale;
72 }
73
74 x = (x * 2.0f - 1.0f) * sc - posi[0];
75 y = (y * 2.0f - 1.0f) * sc - posi[1];
76 float cr = cos(rota * 3.1415926535f / 180.0f);
77 float sr = sin(rota * 3.1415926535f / 180.0f);
78 float tx = x;
79 float ty = y;
80 x = tx * cr - ty * sr;
81 y = tx * sr + ty * cr;
82 x = x * 0.5f + 0.5f;
83 y = y * 0.5f + 0.5f;
84
85 if(!autoTiled)
86 {
87 if(x > numTiles || y > numTiles || x < 0 || y < 0)
88 return NodeOutput({ 0.0f });
89 }
90
91 x = fract(x);
92 y = fract(y);
93 mutex.lock();
94 int xC = (int)(x * (texture->GetWidth()-1));
95 int yC = (int)(y * (texture->GetHeight()-1));
96 unsigned char elevC = texture->GetData()[yC * texture->GetWidth() * 3 + xC * 3 + channel];
97 res = (float)elevC / 256;
98
99 if(npScale)
100 {
101 res = res * 2.0f - 1.0f;
102 }
103
104 if(inv)
105 {
106 res = 1.0f - res;
107 }
108
109 mutex.unlock();
110 return NodeOutput({ res });
111}