I’m almost completely a non-programmer, but I am interested in a very simple question. We have ‘Less Than’ and ‘Greater Than’ math nodes for the compositor and materials. Why don’t we have nodes for ‘Equals To’, ‘Greater Than Or Equal To’, ‘Less Than Or Equal To’. Also, why don’t we have at least rudimentary logical operator nodes for things like AND, OR, and NOT?
I’m rather perplexed by this, since I could go into the source code for Blender, find the part that seemed to say what math nodes do (COM_MathBaseOperation.cpp and/or node_shader_math.c I think?) and, using a snippet from either of them, come up stuff that at least looked right.
For example, a snippet taken from COM_MathBaseOperation.cpp:
void MathLessThanOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
float inputValue2[4];
this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
output[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(output);
}
And now, what I cooked up (sorry it’s not formatted right, I couldn’t figure out how to preserve the formatting):
void MathLessThanOETOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
float inputValue2[4];
this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
output[0] = inputValue1[0] <= inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(output);
}
void MathEqualToOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
float inputValue2[4];
this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
output[0] = inputValue1[0] == inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(output);
}
void MathNotEqualToOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
float inputValue2[4];
this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
output[0] = inputValue1[0] != inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(output);
}
For another example, a snippet from node_shader_math.c:
case NODE_MATH_LOG:
{
/* Don’t want any imaginary numbers… */
if (a > 0 && b > 0)
r = log(a) / log(b);
else
r = 0.0;
break;
}
And now, what I cooked up:
case NODE_MATH_AND:
{
if (a != 0 && b != 0)
r = 1.0;
else
r = 0.0;
break;
}
case NODE_MATH_OR:
{
if (a != 0 || b != 0)
r = 1.0;
else
r = 0.0;
break;
}
case NODE_MATH_NOT:
{
if (a == 0)
r = 1.0;
else
r = 0.0;
break;
}
I’ve learned the basics of how to write in a programming language, but was never really taught ‘big picture stuff’ like what I’m sure is needed for a project as big as blender. I’m sorry if this is a dumb question, but is there some reason why seemingly simple stuff like what I came up with can’t be put in?