seems like only color noise is applied

main
Brett 2023-07-19 19:38:52 -04:00
parent 6a99dba88b
commit f1371a72b4
41 changed files with 108714 additions and 42 deletions

View File

@ -338,3 +338,67 @@
1135 1286 1689721658435138481 parksnrec fc63db74fd58366e
4 1162 1689721703708207229 CMakeFiles/parksnrec.dir/src/genetic/v3/functions_v3.cpp.o 2851fa30bacfc7d5
1162 1306 1689721703851539726 parksnrec fc63db74fd58366e
4 1399 1689804741878229016 CMakeFiles/parksnrec.dir/src/genetic/v3/functions_v3.cpp.o 2851fa30bacfc7d5
4 1629 1689804742108236379 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
4 1876 1689804742354910941 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1876 2074 1689804742554917340 parksnrec fc63db74fd58366e
4 1405 1689804755715338480 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1405 1557 1689804755865343279 parksnrec fc63db74fd58366e
4 1424 1689804819497378617 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1424 1600 1689804819670717495 parksnrec fc63db74fd58366e
4 1436 1689804864358813267 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1436 1593 1689804864515484944 parksnrec fc63db74fd58366e
4 1404 1689805007220654536 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1405 1555 1689805007370679104 parksnrec fc63db74fd58366e
4 1727 1689805082989729199 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
4 1426 1689805090360377427 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1426 1579 1689805090510390350 parksnrec fc63db74fd58366e
4 1410 1689805764990670211 CMakeFiles/parksnrec.dir/src/genetic/v3/functions_v3.cpp.o 2851fa30bacfc7d5
5 1559 1689805765140665375 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1797 1689805765377324410 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1797 1958 1689805765537319251 parksnrec fc63db74fd58366e
4 1693 1689807798184943938 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
4 1740 1689807798231608842 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1740 1907 1689807798398269213 parksnrec fc63db74fd58366e
4 1674 1689807825697237843 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1674 1827 1689807825847232176 parksnrec fc63db74fd58366e
4 1686 1689807888828185705 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1687 1844 1689807888984846452 parksnrec fc63db74fd58366e
4 1635 1689807955862318956 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1635 1785 1689807956012313286 parksnrec fc63db74fd58366e
4 1623 1689808007540365647 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1623 1777 1689808007693693184 parksnrec fc63db74fd58366e
4 1706 1689808495591913183 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
4 1775 1689808495661910536 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1775 1933 1689808495818571278 parksnrec fc63db74fd58366e
5 1710 1689808568602485714 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1793 1689808568682482690 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1793 1946 1689808568835810225 parksnrec fc63db74fd58366e
5 1832 1689808600744603622 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1857 1689808600771269281 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1857 2010 1689808600921263609 parksnrec fc63db74fd58366e
4 1747 1689808707723891585 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1798 1689808707777222902 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1798 1952 1689808707927217230 parksnrec fc63db74fd58366e
5 1718 1689808768204937835 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1792 1689808768278268395 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1792 1945 1689808768428262722 parksnrec fc63db74fd58366e
4 1633 1689809124386956701 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1633 1784 1689809124536979181 parksnrec fc63db74fd58366e
4 1675 1689809160202131031 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1675 1831 1689809160355485697 parksnrec fc63db74fd58366e
5 1648 1689809198617270832 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1648 1798 1689809198767290120 parksnrec fc63db74fd58366e
4 1657 1689809235238469606 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1657 1810 1689809235391821192 parksnrec fc63db74fd58366e
4 1755 1689809266588750048 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1755 1911 1689809266745434194 parksnrec fc63db74fd58366e
4 1687 1689809320334417858 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1687 1841 1689809320487766459 parksnrec fc63db74fd58366e
4 1643 1689809386110532010 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1644 1803 1689809386270545854 parksnrec fc63db74fd58366e
5 1633 1689809444125255471 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
1633 1785 1689809444278600515 parksnrec fc63db74fd58366e
4 1716 1689809894936926601 CMakeFiles/parksnrec.dir/src/genetic/v3/program_v3.cpp.o 7203e7cb37c07468
5 1749 1689809894970260831 CMakeFiles/parksnrec.dir/src/parks/renderer/engine.cpp.o 875432a17ebda434
1749 1905 1689809895123598284 parksnrec fc63db74fd58366e

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
Start testing: Jul 18 19:08 EDT
Start testing: Jul 19 19:38 EDT
----------------------------------------------------------
End testing: Jul 18 19:08 EDT
End testing: Jul 19 19:38 EDT

View File

@ -9,7 +9,7 @@ Size=430,174
Collapsed=1
[Window][Dear ImGui Demo]
Pos=929,405
Pos=1241,122
Size=550,680
Collapsed=1
@ -21,5 +21,5 @@ Collapsed=0
[Window][ImNodes]
Pos=269,23
Size=1157,957
Collapsed=1
Collapsed=0

Binary file not shown.

View File

@ -53,7 +53,8 @@ namespace parks::genetic {
unsigned int requiredColors;
unsigned char acceptsArgs;
public:
Function(std::function<Color(OperatorArguments, ParameterSet)> func, unsigned int requiredScalars, unsigned int requiredColors, unsigned int acceptsArgs): func(std::move(func)), requiredScalars(requiredScalars), requiredColors(requiredColors), acceptsArgs(acceptsArgs) {
const std::string name;
Function(std::string name, std::function<Color(OperatorArguments, ParameterSet)> func, unsigned int requiredScalars, unsigned int requiredColors, unsigned int acceptsArgs): func(std::move(func)), requiredScalars(requiredScalars), requiredColors(requiredColors), acceptsArgs(acceptsArgs), name(std::move(name)) {
}
Function(const Function& f) = delete;
Function& operator=(const Function& f) = delete;
@ -135,21 +136,21 @@ namespace parks::genetic {
};
inline FunctionStorage functions = {
{FunctionID::ADD, new Function{parks::genetic::add, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::SUBTRACT, new Function{parks::genetic::subtract, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MULTIPLY, new Function{parks::genetic::multiply, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::DIVIDE, new Function{parks::genetic::divide, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MOD, new Function{parks::genetic::mod, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ROUND, new Function{parks::genetic::round, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MIN, new Function{parks::genetic::min, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MAX, new Function{parks::genetic::max, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ABS, new Function{parks::genetic::abs, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::LOG, new Function{parks::genetic::log, 0, 0, ARGS_SINGLE | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::SIN, new Function{parks::genetic::sin, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::COS, new Function{parks::genetic::cos, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ATAN, new Function{parks::genetic::atan, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::NOISE, new Function{parks::genetic::noise, 5, 0, ARGS_BOTH | ARGS_VARIABLES}},
{FunctionID::COLOR_NOISE, new Function{parks::genetic::colorNoise, 5, 0, ARGS_BOTH | ARGS_VARIABLES}},
{FunctionID::ADD, new Function{"+", parks::genetic::add, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::SUBTRACT, new Function{"-", parks::genetic::subtract, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MULTIPLY, new Function{"*", parks::genetic::multiply, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::DIVIDE, new Function{"/", parks::genetic::divide, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MOD, new Function{"%", parks::genetic::mod, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ROUND, new Function{"ROUND", parks::genetic::round, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MIN, new Function{"MIN", parks::genetic::min, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::MAX, new Function{"MAX", parks::genetic::max, 0, 0, ARGS_BOTH | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ABS, new Function{"ABS", parks::genetic::abs, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::LOG, new Function{"LOG", parks::genetic::log, 0, 0, ARGS_SINGLE | ARGS_SCALARS | ARGS_COLORS | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::SIN, new Function{"SIN", parks::genetic::sin, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::COS, new Function{"COS", parks::genetic::cos, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::ATAN, new Function{"ATAN", parks::genetic::atan, 0, 0, ARGS_SINGLE | ARGS_VARIABLES | ARGS_FUNCS}},
{FunctionID::NOISE, new Function{"Noise", parks::genetic::noise, 5, 0, ARGS_BOTH | ARGS_VARIABLES}},
{FunctionID::COLOR_NOISE, new Function{"ColorNoise", parks::genetic::colorNoise, 5, 0, ARGS_BOTH | ARGS_VARIABLES}},
};
}

View File

@ -6,6 +6,7 @@
#define PARKSNREC_PROGRAM_V3_H
#include <genetic/v3/functions_v3.h>
#include "ImNodesEz.h"
namespace parks::genetic {
@ -14,7 +15,7 @@ namespace parks::genetic {
unsigned int pos{};
ParameterSet set;
GeneticNode(FunctionID op, unsigned int pos, const ParameterSet& set);
GeneticNode(FunctionID op, unsigned int pos, ParameterSet set);
};
class GeneticTree {
@ -42,23 +43,33 @@ namespace parks::genetic {
static inline int left(int pos){
return 2 * pos;
}
static inline int right(int pos){
return 2 * pos + 1;
}
static inline int parent(int pos){
if (pos <= 0)
return 0;
return (pos) / 2;
return -1;
//if (pos % 2 == 0)
return pos / 2;
//return (pos + 1) / 2;
}
inline GeneticNode* leftNode(int pos){
inline GeneticNode* node(int pos){
if (pos < 0 || pos >= size)
return nullptr;
return nodes[left(pos)];
return nodes[pos];
}
inline GeneticNode* leftNode(int pos){
return node(left(pos));
}
inline GeneticNode* rightNode(int pos){
if (pos < 0 || pos >= size)
return nullptr;
return nodes[right(pos)];
return node(right(pos));
}
static int height(int node);
@ -70,6 +81,10 @@ namespace parks::genetic {
}
}
[[nodiscard]] inline int getSize() const {
return size;
}
~GeneticTree(){
deleteTree();
delete[] nodes;
@ -78,21 +93,44 @@ namespace parks::genetic {
class Program {
private:
struct ImNode_t
{
int height{};
int index{};
FunctionID id;
ImVec2 pos{};
bool selected{};
ImNodes::Ez::SlotInfo inputs[1]{};
ImNodes::Ez::SlotInfo outputs[2]{};
};
std::vector<ImNode_t> treeNodes;
unsigned char pixels[WIDTH * HEIGHT * CHANNELS];
GeneticTree* tree;
static size_t getPixelPosition(unsigned int x, unsigned int y){
return x * CHANNELS + y * WIDTH * CHANNELS;
}
public:
void run();
void regenTreeDisplay();
float getRenderProgress(){
return 0;
float renderProgress;
public:
Program() = default;
void run();
void draw();
[[nodiscard]] float getRenderProgress() const{
return renderProgress;
}
inline unsigned char* getPixels(){
return pixels;
}
~Program(){
delete tree;
}
};
}

View File

@ -4,18 +4,31 @@
#include <genetic/v3/program_v3.h>
#include "imgui.h"
#include <queue>
#include <utility>
namespace parks::genetic {
static inline int pow(int b, int e){
auto o = 1;
for (int i = 0; i < e; i++)
o *= b;
return o;
}
void Program::run() {
if (ImGui::Button("Regen Program And Run")) {
delete tree;
tree = new GeneticTree(7);
regenTreeDisplay();
ParameterSet set = functions[FunctionID::COLOR_NOISE].generateRandomParameters();
for (unsigned int i = 0; i < WIDTH; i++) {
for (unsigned int j = 0; j < HEIGHT; j++){
auto pos = getPixelPosition(i, j);
auto out = functions[FunctionID::COLOR_NOISE].call({ARGS_BOTH, Color((double)i / WIDTH), Color((double)j / HEIGHT)}, set);
//auto out = functions[FunctionID::COLOR_NOISE].call({ARGS_BOTH, Color((double)i / WIDTH), Color((double)j / HEIGHT)}, set);
auto out = tree->execute((double)i / WIDTH, (double)j / HEIGHT);
pixels[pos] = (unsigned char)(out.r * 255);
pixels[pos + 1] = (unsigned char) (out.g * 255);
@ -44,8 +57,63 @@ namespace parks::genetic {
}
}
GeneticNode::GeneticNode(FunctionID op, unsigned int pos, const ParameterSet& set):
op(op), pos(pos), set(set) {}
void Program::regenTreeDisplay() {
treeNodes = {};
for (int i = 0; i < tree->getSize(); i++){
auto node = tree->node(i);
if (node == nullptr)
continue;
auto height = GeneticTree::height(i);
ImNode_t n;
n.height = height;
n.id = node->op;
n.index = i;
n.selected = false;
n.pos = {(float)i * 200, 0};
n.inputs[0] = {"In", 1};
n.outputs[0] = {"Left", 1};
n.outputs[1] = {"Right", 1};
treeNodes.push_back(n);
}
}
void Program::draw() {
static ImNodes::Ez::Context* context = ImNodes::Ez::CreateContext();
IM_UNUSED(context);
if (ImGui::Begin("ImNodes", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
{
ImNodes::Ez::BeginCanvas();
for (ImNode_t& node : treeNodes)
{
if (ImNodes::Ez::BeginNode(&node, ("H: " + std::to_string(node.height) + " | I: " + std::to_string(node.index) + " : " + functions[node.id].name).c_str(), &node.pos, &node.selected))
{
ImNodes::Ez::InputSlots(node.inputs, 1);
ImNodes::Ez::OutputSlots(node.outputs, 2);
ImNodes::Ez::EndNode();
}
// auto p = GeneticTree::parent(node.index);
// auto parent = tree->node(p);
// if (p >= 0 && parent != nullptr) {
// //BLT_TRACE("Parent i: %d, Parent %d for input node %d", p, parent, node.index);
// if (GeneticTree::left(p) == node.index)
// ImNodes::Connection(&node, "In", &parent, "Left");
// else
// ImNodes::Connection(&node, "In", &parent, "Right");
// }
}
//ImNodes::Connection(&nodes[2], "In", &nodes[0], "Out");
ImNodes::Ez::EndCanvas();
}
ImGui::End();
}
GeneticNode::GeneticNode(FunctionID op, unsigned int pos, ParameterSet set):
op(op), pos(pos), set(std::move(set)) {}
void GeneticTree::generateRandomTree() {
std::queue<int> nodesToProcess;
@ -57,10 +125,10 @@ namespace parks::genetic {
if (node >= size)
continue;
// end early by constructing a leaf
if (chance(5)){
continue;
}
// // end early by constructing a leaf
// if (chance(5)){
// continue;
// }
auto op = functions.select();
auto& func = functions[op];
@ -85,8 +153,8 @@ namespace parks::genetic {
}
int GeneticTree::height(int node) {
int height = 1;
while ((node = parent(node)) != 0)
int height = 0;
while ((node = parent(node)) != -1)
height++;
return height;
}
@ -115,12 +183,24 @@ namespace parks::genetic {
if (rNode != nullptr)
rightC = execute_internal(x, y, r);
} else {
if (func.allowedColors())
std::vector<Color> lefts;
std::vector<Color> rights;
if (func.allowedColors()) {
lefts.push_back(RandomColor::get());
rights.push_back(RandomColor::get());
}
return Color(0, 0, 0);
if (func.allowedScalars()) {
lefts.push_back(RandomScalar::get());
rights.push_back(RandomScalar::get());
}
if (func.allowedVariables()) {
lefts.emplace_back(x);
rights.emplace_back(y);
}
leftC = lefts[randomInt(0, (int)lefts.size()-1)];
rightC = rights[randomInt(0, (int)rights.size()-1)];
}
return func.call({ARGS_SINGLE, leftC, rightC}, ourNode->set);
}
}

View File

@ -76,6 +76,7 @@ namespace parks {
ImGui::Checkbox("Show Image Output?", &showImage);
p->run();
ImGui::End();
p->draw();
geneticImageTexture.upload(p->getPixels(), GL_UNSIGNED_BYTE, WIDTH, HEIGHT, CHANNELS);
if (showImage) {