Skip to content

Commit 838023b

Browse files
authored
Upgraded code to last version of raylib (#6)
1 parent cdb2259 commit 838023b

File tree

4 files changed

+52
-55
lines changed

4 files changed

+52
-55
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Installation
1212
FNode requires raylib. To get it, follow the next steps:
1313

1414
* Go to [raylib](https://github.com/raysan5/raylib) and clone the repository.
15-
* Ensure to pull the changes of tag [v2.0.0](https://github.com/raysan5/raylib/releases/tag/2.0.0).
15+
* Ensure to pull the last changes from master branch.
1616
* Use code inside examples header comments to compile and execute.
1717

1818

release/fnode_shader_editor.exe

216 KB
Binary file not shown.

src/fnode.h

-7
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ FNODEDEF void DestroyNodeLine(FLine line);
207207
FNODEDEF void DestroyComment(FComment comment); // Destroys a comment
208208
FNODEDEF void CloseFNode(); // Unitializes FNode global variables
209209
FNODEDEF void TraceLogFNode(bool error, const char *text, ...); // Outputs a trace log message
210-
FNODEDEF void SetLineWidth(float width); // Sets GL state machine line width
211210
FNODEDEF int FSearch(char *filename, char *string); // Returns 1 if a specific string is found in a text file
212211

213212
#if defined(__cplusplus)
@@ -2227,12 +2226,6 @@ FNODEDEF void TraceLogFNode(bool error, const char *text, ...)
22272226
if (error) exit(1);
22282227
}
22292228

2230-
// Sets GL state machine line width
2231-
FNODEDEF void SetLineWidth(float width)
2232-
{
2233-
glLineWidth(width);
2234-
}
2235-
22362229
// Returns 1 if a specific string is found in a text file
22372230
FNODEDEF int FSearch(char *filename, char *string)
22382231
{

src/fnode_shader_editor.c

+51-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**********************************************************************************************
22
*
3-
* FNode 1.0 - Visual Scripting Tool To Build GLSL Shaders
3+
* FNode 1.1 - Visual Scripting Tool To Build GLSL Shaders
44
*
55
* DESCRIPTION:
66
*
@@ -27,12 +27,12 @@
2727
*
2828
*
2929
* Use the following code to compile:
30-
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s icon\fnode -lraylib -lpthread -lopengl32 -lgdi32 -std=c99
30+
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s icon\fnode_icon -lraylib -lopengl32 -lgdi32 -std=c99
3131
*
3232
*
3333
* LICENSE: zlib/libpng
3434
*
35-
* Copyright (c) 2016-2018 Victor Fisac
35+
* Copyright (c) 2016-2020 Victor Fisac
3636
*
3737
* This software is provided "as-is", without any express or implied warranty. In no event
3838
* will the authors be held liable for any damages arising from the use of this software.
@@ -60,6 +60,10 @@
6060
//----------------------------------------------------------------------------------
6161
// Defines and Macros
6262
//----------------------------------------------------------------------------------
63+
#define CHAR_SIZE 512 // Shader output max size for text
64+
#define MAX_TEXTURES 8 // Shader maximum OpenGL texture units
65+
#define DEFAULT_PROJECT_TEXTURES 2 // Textures to load when loading default project
66+
#define COMPILE_DURATION 120 // Shader compile result duration
6367
#define UI_PADDING 25 // Interface bounds padding with background
6468
#define UI_PADDING_SCROLL 0 // Interface scroll bar padding
6569
#define UI_BUTTON_HEIGHT 30 // Interface bounds height
@@ -74,17 +78,15 @@
7478
#define EXAMPLE_VERTEX_PATH "res/example/output/shader.vs" // Vertex shader output path of start example
7579
#define EXAMPLE_FRAGMENT_PATH "res/example/output/shader.fs" // Fragment shader output path of start example
7680
#define EXAMPLE_DATA_PATH "res/example/output/shader.fnode" // Shader data output path of start example
77-
#define MAX_TEXTURES 8 // Shader maximum OpenGL texture units
78-
#define DEFAULT_PROJECT_TEXTURES 2 // Textures to load when loading default project
79-
#define COMPILE_DURATION 120 // Shader compile result duration
8081
#define MODEL_PATH "res/example/meshes/plant.obj" // Example model file path
8182
#define MODEL_TEXTURE_DIFFUSE "res/example/textures/plant_color.png" // Example model color texture file path
8283
#define MODEL_TEXTURE_WINDAMOUNT "res/example/textures/plant_motion.png" // Example model motion texture file path
8384
#define FXAA_VERTEX "res/shaders/fxaa.vs" // Visor FXAA vertex shader path
8485
#define FXAA_FRAGMENT "res/shaders/fxaa.fs" // Visor FXAA fragment shader path
85-
#define FXAA_SCREENSIZE_UNIFORM "viewportSize" // Visor FXAA shader screen size uniform location name
8686
#define WINDOW_ICON "res/fnode_icon.png" // FNode icon for window initialization
8787

88+
#define FXAA_SCREENSIZE_UNIFORM "viewportSize" // Visor FXAA shader screen size uniform location name
89+
8890
#define LEFT_LAYOUT_RECT (Rectangle){ layoutRect.x, layoutRect.y + (UI_BUTTON_HEIGHT + PADDING_MAIN_CENTER)*menuOffset, layoutRect.width, UI_BUTTON_HEIGHT }
8991
#define RIGHT_LAYOUT_RECT (Rectangle){ layoutRect.x, layoutRect.y + (UI_BUTTON_HEIGHT + PADDING_MAIN_CENTER)*menuOffset, layoutRect.width, layoutRect.height }
9092

@@ -234,14 +236,17 @@ void CheckPreviousShader(bool makeGraph)
234236
if (previousShader.id > 0)
235237
{
236238
shader = previousShader;
237-
model.material.shader = shader;
239+
model.materials[0].shader = shader;
238240
viewUniform = GetShaderLocation(shader, "viewDirection");
239241
transformUniform = GetShaderLocation(shader, "modelMatrix");
240242
timeUniformV = GetShaderLocation(shader, "vertCurrentTime");
241243
timeUniformF = GetShaderLocation(shader, "fragCurrentTime");
242244

245+
shader.locs[LOC_MAP_ALBEDO] = glGetUniformLocation(shader.id, "texture0");
246+
shader.locs[LOC_MAP_NORMAL] = glGetUniformLocation(shader.id, "texture1");
247+
shader.locs[LOC_MAP_METALNESS] = glGetUniformLocation(shader.id, "texture2");
243248
shader.locs[LOC_MAP_ROUGHNESS] = glGetUniformLocation(shader.id, "texture3");
244-
shader.locs[LOC_MAP_OCCUSION] = glGetUniformLocation(shader.id, "texture4");
249+
shader.locs[LOC_MAP_OCCLUSION] = glGetUniformLocation(shader.id, "texture4");
245250
shader.locs[LOC_MAP_EMISSION] = glGetUniformLocation(shader.id, "texture5");
246251
shader.locs[LOC_MAP_HEIGHT] = glGetUniformLocation(shader.id, "texture6");
247252
shader.locs[LOC_MAP_BRDF] = glGetUniformLocation(shader.id, "texture7");
@@ -391,12 +396,12 @@ void LoadDefaultProject(void)
391396
{
392397
SetTextureFilter(textures[i], FILTER_BILINEAR);
393398
texPaths[i] = MODEL_TEXTURE_WINDAMOUNT;
394-
model.material.maps[i].texture = textures[i];
399+
model.materials[0].maps[i].texture = textures[i];
395400
}
396401
}
397402

398403
shader = previousShader;
399-
model.material.shader = shader;
404+
model.materials[0].shader = shader;
400405
viewUniform = GetShaderLocation(shader, "viewDirection");
401406
transformUniform = GetShaderLocation(shader, "modelMatrix");
402407
timeUniformV = GetShaderLocation(shader, "vertCurrentTime");
@@ -1245,7 +1250,7 @@ void UpdateShaderData(void)
12451250

12461251
if (shader.id > 0)
12471252
{
1248-
model.material.maps[index].texture = textures[index];
1253+
model.materials[0].maps[index].texture = textures[index];
12491254
SetTextureFilter(textures[index], FILTER_BILINEAR);
12501255
}
12511256

@@ -1256,15 +1261,15 @@ void UpdateShaderData(void)
12561261
else if (CheckModelExtension(droppedFiles[0]) && !loadedModel)
12571262
{
12581263
model = LoadModel(droppedFiles[0]);
1259-
model.material.shader = shader;
1264+
model.materials[0].shader = shader;
12601265

12611266
for (int i = 0; i < MAX_TEXTURES; i++)
12621267
{
12631268
if (textures[i].id != 0)
12641269
{
1265-
model.material.maps[i].texture = textures[i];
1266-
model.material.maps[i].color = WHITE;
1267-
model.material.maps[i].value = 1.0f;
1270+
model.materials[0].maps[i].texture = textures[i];
1271+
model.materials[0].maps[i].color = WHITE;
1272+
model.materials[0].maps[i].value = 1.0f;
12681273
}
12691274
}
12701275

@@ -1283,7 +1288,7 @@ void UpdateShaderData(void)
12831288
Vector3 viewVector = { camera3d.position.x - camera3d.target.x, camera3d.position.y - camera3d.target.y, camera3d.position.z - camera3d.target.z };
12841289
viewVector = FVector3Normalize(viewVector);
12851290
float viewDir[3] = { viewVector.x, viewVector.y, viewVector.z };
1286-
SetShaderValue(shader, viewUniform, viewDir, 3);
1291+
SetShaderValue(shader, viewUniform, viewDir, UNIFORM_VEC3);
12871292
}
12881293

12891294
// Check if model transform matrix is used in shader and send it if needed
@@ -1294,19 +1299,19 @@ void UpdateShaderData(void)
12941299
{
12951300
// Convert time value to float array and send it to shader
12961301
float time[1] = { currentTime };
1297-
SetShaderValue(shader, timeUniformV, time, 1);
1302+
SetShaderValue(shader, timeUniformV, time, UNIFORM_FLOAT);
12981303
}
12991304

13001305
// Check if current time is used in fragment shader
13011306
if (timeUniformF != -1)
13021307
{
13031308
// Convert time value to float array and send it to shader
13041309
float time[1] = { currentTime };
1305-
SetShaderValue(shader, timeUniformF, time, 1);
1310+
SetShaderValue(shader, timeUniformF, time, UNIFORM_FLOAT);
13061311
}
13071312

13081313
float resolution[2] = { (fullVisor ? screenSize.x : (screenSize.x/4)), (fullVisor ? screenSize.y : (screenSize.y/4)) };
1309-
SetShaderValue(fxaa, fxaaUniform, resolution, 2);
1314+
SetShaderValue(fxaa, fxaaUniform, resolution, UNIFORM_VEC2);
13101315
}
13111316
}
13121317

@@ -1396,7 +1401,7 @@ void CompileShader(void)
13961401
remove(VERTEX_PATH);
13971402
remove(FRAGMENT_PATH);
13981403

1399-
model.material.shader = GetShaderDefault();
1404+
model.materials[0].shader = GetShaderDefault();
14001405
for (int i = 0; i < MAX_TEXTURES; i++) usedUnits[i] = false;
14011406
viewUniform = -1;
14021407
transformUniform = -1;
@@ -1805,7 +1810,7 @@ void CompileNode(FNode node, FILE *file, bool fragment)
18051810
case FNODE_MVP: strcat(body, "mvp;\n"); break;
18061811
case FNODE_SAMPLER2D:
18071812
{
1808-
char test[128] = { '\0' };
1813+
char test[CHAR_SIZE] = { '\0' };
18091814

18101815
int indexA = GetNodeIndex(node->inputs[0]);
18111816
int indexB = GetNodeIndex(node->inputs[1]);
@@ -1884,7 +1889,7 @@ void CompileNode(FNode node, FILE *file, bool fragment)
18841889
}
18851890
else if (node->type >= FNODE_APPEND)
18861891
{
1887-
char temp[128] = { '\0' };
1892+
char temp[CHAR_SIZE] = { '\0' };
18881893
switch (node->type)
18891894
{
18901895
case FNODE_APPEND:
@@ -1939,8 +1944,8 @@ void CompileNode(FNode node, FILE *file, bool fragment)
19391944
case FNODE_POWER: sprintf(temp, "pow(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1]); break;
19401945
case FNODE_STEP: sprintf(temp, "((node_%02i <= node_%02i) ? 1.0 : 0.0);\n", node->inputs[0], node->inputs[1]); break;
19411946
case FNODE_POSTERIZE: sprintf(temp, "floor(node_%02i*node_%02i)/node_%02i;\n", node->inputs[0], node->inputs[1], node->inputs[1]); break;
1942-
case FNODE_MAX: sprintf(temp, "max(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1], node->inputs[1]); break;
1943-
case FNODE_MIN: sprintf(temp, "min(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1], node->inputs[1]); break;
1947+
case FNODE_MAX: sprintf(temp, "max(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1]); break;
1948+
case FNODE_MIN: sprintf(temp, "min(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1]); break;
19441949
case FNODE_LERP: sprintf(temp, "mix(node_%02i, node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1], node->inputs[2]); break;
19451950
case FNODE_SMOOTHSTEP: sprintf(temp, "smoothstep(node_%02i, node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1], node->inputs[2]); break;
19461951
case FNODE_CROSSPRODUCT: sprintf(temp, "cross(node_%02i, node_%02i);\n", node->inputs[0], node->inputs[1]); break;
@@ -2053,28 +2058,30 @@ void DrawCanvas(void)
20532058

20542059
BeginTextureMode(gridTarget);
20552060

2061+
ClearBackground(RAYWHITE);
2062+
20562063
// Draw background title and credits
20572064
DrawText("FNODE 1.0", (screenSize.x - MeasureText("FNODE 1.0", 120))/2, screenSize.y/2 - 60, 120, Fade(LIGHTGRAY, UI_GRID_ALPHA*2));
20582065
DrawText("VICTOR FISAC", (screenSize.x - MeasureText("VICTOR FISAC", 40))/2, screenSize.y*0.65f - 20, 40, Fade(LIGHTGRAY, UI_GRID_ALPHA*2));
20592066

2060-
Begin2dMode(camera);
2067+
BeginMode2D(camera);
20612068

20622069
DrawCanvasGrid(UI_GRID_COUNT);
20632070

2064-
End2dMode();
2071+
EndMode2D();
20652072

20662073
EndTextureMode();
20672074

20682075
DrawTexturePro(gridTarget.texture, (Rectangle){ 0, 0, gridTarget.texture.width, -gridTarget.texture.height }, (Rectangle){ 0, 0, screenSize.x, screenSize.y }, (Vector2){ 0, 0 }, 0, WHITE);
20692076

2070-
Begin2dMode(camera);
2077+
BeginMode2D(camera);
20712078

20722079
// Draw all created comments, lines and nodes
20732080
for (int i = 0; i < commentsCount; i++) DrawComment(comments[i]);
20742081
for (int i = 0; i < nodesCount; i++) DrawNode(nodes[i]);
20752082
for (int i = 0; i < linesCount; i++) DrawNodeLine(lines[i]);
20762083

2077-
End2dMode();
2084+
EndMode2D();
20782085

20792086
EndShaderMode();
20802087
}
@@ -2107,20 +2114,22 @@ void DrawCanvasGrid(int divisions)
21072114
void DrawVisor(void)
21082115
{
21092116
BeginTextureMode(visorTarget);
2117+
2118+
ClearBackground(RAYWHITE);
21102119

21112120
DrawRectangle(0, 0, screenSize.x, screenSize.y, GRAY);
21122121

21132122
// Draw background title and credits
21142123
DrawText("FNODE 1.0", (screenSize.x - MeasureText("FNODE 1.0", 120))/2, screenSize.y/2 - 60, 120, Fade(LIGHTGRAY, UI_GRID_ALPHA*2));
21152124
DrawText("VICTOR FISAC", (screenSize.x - MeasureText("VICTOR FISAC", 40))/2, screenSize.y*0.65f - 20, 40, Fade(LIGHTGRAY, UI_GRID_ALPHA*2));
21162125

2117-
BeginShaderMode(model.material.shader);
2126+
BeginShaderMode(model.materials[0].shader);
21182127

2119-
Begin3dMode(camera3d);
2128+
BeginMode3D(camera3d);
21202129

21212130
DrawModelEx(model, (Vector3){ 0.0f, -1.0f, 0.0f }, (Vector3){ 0, 1, 0 }, modelRotation, (Vector3){ VISOR_MODEL_SCALE, VISOR_MODEL_SCALE, VISOR_MODEL_SCALE }, WHITE);
21222131

2123-
End3dMode();
2132+
EndMode3D();
21242133

21252134
EndShaderMode();
21262135

@@ -2149,7 +2158,7 @@ void DrawVisor(void)
21492158

21502159
// Draw interface to create nodes
21512160
void DrawInterface(void)
2152-
{
2161+
{
21532162
DrawHelp();
21542163

21552164
sidebarRect = (Rectangle){ 0, 0, screenSize.x - canvasSize.x, screenSize.y };
@@ -2191,16 +2200,7 @@ void DrawInterface(void)
21912200
if (InterfaceButton((Rectangle){ layoutRect.x + layoutRect.width - 30, layoutRect.y + 4, 22, 22 }, "X"))
21922201
{
21932202
loadedModel = false;
2194-
UnloadMesh(&model.mesh);
2195-
2196-
for (int i = 0; i < MAX_TEXTURES; i++)
2197-
{
2198-
if (texPaths[i] != NULL)
2199-
{
2200-
textures[i] = LoadTexture(texPaths[i]);
2201-
SetTextureFilter(textures[i], FILTER_BILINEAR);
2202-
}
2203-
}
2203+
UnloadModel(model);
22042204
}
22052205
}
22062206
else DrawText("DROP MESH HERE", layoutRect.x + MeasureText("DROP MESH HERE", 10)/2 - PADDING_MAIN_LEFT, layoutRect.y + UI_BUTTON_HEIGHT/2 - WIDTH_INTERFACE_BORDER*2 - 2, 10, COLOR_BUTTON_BORDER);
@@ -2549,12 +2549,16 @@ int main(void)
25492549
// Initialization
25502550
//--------------------------------------------------------------------------------------
25512551
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
2552-
InitWindow(screenSize.x, screenSize.y, "FNode - Visual Scripting Tool To Build GLSL Shaders");
2552+
InitWindow(screenSize.x, screenSize.y, "[fnode] Create shaders with visual scripting");
25532553
iconTex = LoadTexture(WINDOW_ICON);
25542554

25552555
// Load resources
25562556
model = LoadModel(MODEL_PATH);
2557-
if (model.mesh.vertexCount > 0) loadedModel = true;
2557+
MeshTangents(&model.meshes[0]);
2558+
2559+
if (model.meshCount > 0)
2560+
loadedModel = true;
2561+
25582562
visorTarget = LoadRenderTexture(screenSize.x/4, screenSize.y/4);
25592563
gridTarget = LoadRenderTexture(screenSize.x, screenSize.y);
25602564
fxaa = LoadShader(FXAA_VERTEX, FXAA_FRAGMENT);
@@ -2577,7 +2581,6 @@ int main(void)
25772581
UpdateCamera(&camera3d);
25782582

25792583
SetTargetFPS(60);
2580-
SetLineWidth(3);
25812584
//--------------------------------------------------------------------------------------
25822585

25832586
// Main game loop
@@ -2624,7 +2627,8 @@ int main(void)
26242627
DrawInterface();
26252628
}
26262629

2627-
if (drawVisor) DrawVisor();
2630+
if (drawVisor)
2631+
DrawVisor();
26282632

26292633
EndDrawing();
26302634
//----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)