1
1
/**********************************************************************************************
2
2
*
3
- * FNode 1.0 - Visual Scripting Tool To Build GLSL Shaders
3
+ * FNode 1.1 - Visual Scripting Tool To Build GLSL Shaders
4
4
*
5
5
* DESCRIPTION:
6
6
*
27
27
*
28
28
*
29
29
* 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
31
31
*
32
32
*
33
33
* LICENSE: zlib/libpng
34
34
*
35
- * Copyright (c) 2016-2018 Victor Fisac
35
+ * Copyright (c) 2016-2020 Victor Fisac
36
36
*
37
37
* This software is provided "as-is", without any express or implied warranty. In no event
38
38
* will the authors be held liable for any damages arising from the use of this software.
60
60
//----------------------------------------------------------------------------------
61
61
// Defines and Macros
62
62
//----------------------------------------------------------------------------------
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
63
67
#define UI_PADDING 25 // Interface bounds padding with background
64
68
#define UI_PADDING_SCROLL 0 // Interface scroll bar padding
65
69
#define UI_BUTTON_HEIGHT 30 // Interface bounds height
74
78
#define EXAMPLE_VERTEX_PATH "res/example/output/shader.vs" // Vertex shader output path of start example
75
79
#define EXAMPLE_FRAGMENT_PATH "res/example/output/shader.fs" // Fragment shader output path of start example
76
80
#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
80
81
#define MODEL_PATH "res/example/meshes/plant.obj" // Example model file path
81
82
#define MODEL_TEXTURE_DIFFUSE "res/example/textures/plant_color.png" // Example model color texture file path
82
83
#define MODEL_TEXTURE_WINDAMOUNT "res/example/textures/plant_motion.png" // Example model motion texture file path
83
84
#define FXAA_VERTEX "res/shaders/fxaa.vs" // Visor FXAA vertex shader path
84
85
#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
86
86
#define WINDOW_ICON "res/fnode_icon.png" // FNode icon for window initialization
87
87
88
+ #define FXAA_SCREENSIZE_UNIFORM "viewportSize" // Visor FXAA shader screen size uniform location name
89
+
88
90
#define LEFT_LAYOUT_RECT (Rectangle){ layoutRect.x, layoutRect.y + (UI_BUTTON_HEIGHT + PADDING_MAIN_CENTER)*menuOffset, layoutRect.width, UI_BUTTON_HEIGHT }
89
91
#define RIGHT_LAYOUT_RECT (Rectangle){ layoutRect.x, layoutRect.y + (UI_BUTTON_HEIGHT + PADDING_MAIN_CENTER)*menuOffset, layoutRect.width, layoutRect.height }
90
92
@@ -234,14 +236,17 @@ void CheckPreviousShader(bool makeGraph)
234
236
if (previousShader .id > 0 )
235
237
{
236
238
shader = previousShader ;
237
- model .material .shader = shader ;
239
+ model .materials [ 0 ] .shader = shader ;
238
240
viewUniform = GetShaderLocation (shader , "viewDirection" );
239
241
transformUniform = GetShaderLocation (shader , "modelMatrix" );
240
242
timeUniformV = GetShaderLocation (shader , "vertCurrentTime" );
241
243
timeUniformF = GetShaderLocation (shader , "fragCurrentTime" );
242
244
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" );
243
248
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" );
245
250
shader .locs [LOC_MAP_EMISSION ] = glGetUniformLocation (shader .id , "texture5" );
246
251
shader .locs [LOC_MAP_HEIGHT ] = glGetUniformLocation (shader .id , "texture6" );
247
252
shader .locs [LOC_MAP_BRDF ] = glGetUniformLocation (shader .id , "texture7" );
@@ -391,12 +396,12 @@ void LoadDefaultProject(void)
391
396
{
392
397
SetTextureFilter (textures [i ], FILTER_BILINEAR );
393
398
texPaths [i ] = MODEL_TEXTURE_WINDAMOUNT ;
394
- model .material .maps [i ].texture = textures [i ];
399
+ model .materials [ 0 ] .maps [i ].texture = textures [i ];
395
400
}
396
401
}
397
402
398
403
shader = previousShader ;
399
- model .material .shader = shader ;
404
+ model .materials [ 0 ] .shader = shader ;
400
405
viewUniform = GetShaderLocation (shader , "viewDirection" );
401
406
transformUniform = GetShaderLocation (shader , "modelMatrix" );
402
407
timeUniformV = GetShaderLocation (shader , "vertCurrentTime" );
@@ -1245,7 +1250,7 @@ void UpdateShaderData(void)
1245
1250
1246
1251
if (shader .id > 0 )
1247
1252
{
1248
- model .material .maps [index ].texture = textures [index ];
1253
+ model .materials [ 0 ] .maps [index ].texture = textures [index ];
1249
1254
SetTextureFilter (textures [index ], FILTER_BILINEAR );
1250
1255
}
1251
1256
@@ -1256,15 +1261,15 @@ void UpdateShaderData(void)
1256
1261
else if (CheckModelExtension (droppedFiles [0 ]) && !loadedModel )
1257
1262
{
1258
1263
model = LoadModel (droppedFiles [0 ]);
1259
- model .material .shader = shader ;
1264
+ model .materials [ 0 ] .shader = shader ;
1260
1265
1261
1266
for (int i = 0 ; i < MAX_TEXTURES ; i ++ )
1262
1267
{
1263
1268
if (textures [i ].id != 0 )
1264
1269
{
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 ;
1268
1273
}
1269
1274
}
1270
1275
@@ -1283,7 +1288,7 @@ void UpdateShaderData(void)
1283
1288
Vector3 viewVector = { camera3d .position .x - camera3d .target .x , camera3d .position .y - camera3d .target .y , camera3d .position .z - camera3d .target .z };
1284
1289
viewVector = FVector3Normalize (viewVector );
1285
1290
float viewDir [3 ] = { viewVector .x , viewVector .y , viewVector .z };
1286
- SetShaderValue (shader , viewUniform , viewDir , 3 );
1291
+ SetShaderValue (shader , viewUniform , viewDir , UNIFORM_VEC3 );
1287
1292
}
1288
1293
1289
1294
// Check if model transform matrix is used in shader and send it if needed
@@ -1294,19 +1299,19 @@ void UpdateShaderData(void)
1294
1299
{
1295
1300
// Convert time value to float array and send it to shader
1296
1301
float time [1 ] = { currentTime };
1297
- SetShaderValue (shader , timeUniformV , time , 1 );
1302
+ SetShaderValue (shader , timeUniformV , time , UNIFORM_FLOAT );
1298
1303
}
1299
1304
1300
1305
// Check if current time is used in fragment shader
1301
1306
if (timeUniformF != -1 )
1302
1307
{
1303
1308
// Convert time value to float array and send it to shader
1304
1309
float time [1 ] = { currentTime };
1305
- SetShaderValue (shader , timeUniformF , time , 1 );
1310
+ SetShaderValue (shader , timeUniformF , time , UNIFORM_FLOAT );
1306
1311
}
1307
1312
1308
1313
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 );
1310
1315
}
1311
1316
}
1312
1317
@@ -1396,7 +1401,7 @@ void CompileShader(void)
1396
1401
remove (VERTEX_PATH );
1397
1402
remove (FRAGMENT_PATH );
1398
1403
1399
- model .material .shader = GetShaderDefault ();
1404
+ model .materials [ 0 ] .shader = GetShaderDefault ();
1400
1405
for (int i = 0 ; i < MAX_TEXTURES ; i ++ ) usedUnits [i ] = false;
1401
1406
viewUniform = -1 ;
1402
1407
transformUniform = -1 ;
@@ -1805,7 +1810,7 @@ void CompileNode(FNode node, FILE *file, bool fragment)
1805
1810
case FNODE_MVP : strcat (body , "mvp;\n" ); break ;
1806
1811
case FNODE_SAMPLER2D :
1807
1812
{
1808
- char test [128 ] = { '\0' };
1813
+ char test [CHAR_SIZE ] = { '\0' };
1809
1814
1810
1815
int indexA = GetNodeIndex (node -> inputs [0 ]);
1811
1816
int indexB = GetNodeIndex (node -> inputs [1 ]);
@@ -1884,7 +1889,7 @@ void CompileNode(FNode node, FILE *file, bool fragment)
1884
1889
}
1885
1890
else if (node -> type >= FNODE_APPEND )
1886
1891
{
1887
- char temp [128 ] = { '\0' };
1892
+ char temp [CHAR_SIZE ] = { '\0' };
1888
1893
switch (node -> type )
1889
1894
{
1890
1895
case FNODE_APPEND :
@@ -1939,8 +1944,8 @@ void CompileNode(FNode node, FILE *file, bool fragment)
1939
1944
case FNODE_POWER : sprintf (temp , "pow(node_%02i, node_%02i);\n" , node -> inputs [0 ], node -> inputs [1 ]); break ;
1940
1945
case FNODE_STEP : sprintf (temp , "((node_%02i <= node_%02i) ? 1.0 : 0.0);\n" , node -> inputs [0 ], node -> inputs [1 ]); break ;
1941
1946
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 ;
1944
1949
case FNODE_LERP : sprintf (temp , "mix(node_%02i, node_%02i, node_%02i);\n" , node -> inputs [0 ], node -> inputs [1 ], node -> inputs [2 ]); break ;
1945
1950
case FNODE_SMOOTHSTEP : sprintf (temp , "smoothstep(node_%02i, node_%02i, node_%02i);\n" , node -> inputs [0 ], node -> inputs [1 ], node -> inputs [2 ]); break ;
1946
1951
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)
2053
2058
2054
2059
BeginTextureMode (gridTarget );
2055
2060
2061
+ ClearBackground (RAYWHITE );
2062
+
2056
2063
// Draw background title and credits
2057
2064
DrawText ("FNODE 1.0" , (screenSize .x - MeasureText ("FNODE 1.0" , 120 ))/2 , screenSize .y /2 - 60 , 120 , Fade (LIGHTGRAY , UI_GRID_ALPHA * 2 ));
2058
2065
DrawText ("VICTOR FISAC" , (screenSize .x - MeasureText ("VICTOR FISAC" , 40 ))/2 , screenSize .y * 0.65f - 20 , 40 , Fade (LIGHTGRAY , UI_GRID_ALPHA * 2 ));
2059
2066
2060
- Begin2dMode (camera );
2067
+ BeginMode2D (camera );
2061
2068
2062
2069
DrawCanvasGrid (UI_GRID_COUNT );
2063
2070
2064
- End2dMode ();
2071
+ EndMode2D ();
2065
2072
2066
2073
EndTextureMode ();
2067
2074
2068
2075
DrawTexturePro (gridTarget .texture , (Rectangle ){ 0 , 0 , gridTarget .texture .width , - gridTarget .texture .height }, (Rectangle ){ 0 , 0 , screenSize .x , screenSize .y }, (Vector2 ){ 0 , 0 }, 0 , WHITE );
2069
2076
2070
- Begin2dMode (camera );
2077
+ BeginMode2D (camera );
2071
2078
2072
2079
// Draw all created comments, lines and nodes
2073
2080
for (int i = 0 ; i < commentsCount ; i ++ ) DrawComment (comments [i ]);
2074
2081
for (int i = 0 ; i < nodesCount ; i ++ ) DrawNode (nodes [i ]);
2075
2082
for (int i = 0 ; i < linesCount ; i ++ ) DrawNodeLine (lines [i ]);
2076
2083
2077
- End2dMode ();
2084
+ EndMode2D ();
2078
2085
2079
2086
EndShaderMode ();
2080
2087
}
@@ -2107,20 +2114,22 @@ void DrawCanvasGrid(int divisions)
2107
2114
void DrawVisor (void )
2108
2115
{
2109
2116
BeginTextureMode (visorTarget );
2117
+
2118
+ ClearBackground (RAYWHITE );
2110
2119
2111
2120
DrawRectangle (0 , 0 , screenSize .x , screenSize .y , GRAY );
2112
2121
2113
2122
// Draw background title and credits
2114
2123
DrawText ("FNODE 1.0" , (screenSize .x - MeasureText ("FNODE 1.0" , 120 ))/2 , screenSize .y /2 - 60 , 120 , Fade (LIGHTGRAY , UI_GRID_ALPHA * 2 ));
2115
2124
DrawText ("VICTOR FISAC" , (screenSize .x - MeasureText ("VICTOR FISAC" , 40 ))/2 , screenSize .y * 0.65f - 20 , 40 , Fade (LIGHTGRAY , UI_GRID_ALPHA * 2 ));
2116
2125
2117
- BeginShaderMode (model .material .shader );
2126
+ BeginShaderMode (model .materials [ 0 ] .shader );
2118
2127
2119
- Begin3dMode (camera3d );
2128
+ BeginMode3D (camera3d );
2120
2129
2121
2130
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 );
2122
2131
2123
- End3dMode ();
2132
+ EndMode3D ();
2124
2133
2125
2134
EndShaderMode ();
2126
2135
@@ -2149,7 +2158,7 @@ void DrawVisor(void)
2149
2158
2150
2159
// Draw interface to create nodes
2151
2160
void DrawInterface (void )
2152
- {
2161
+ {
2153
2162
DrawHelp ();
2154
2163
2155
2164
sidebarRect = (Rectangle ){ 0 , 0 , screenSize .x - canvasSize .x , screenSize .y };
@@ -2191,16 +2200,7 @@ void DrawInterface(void)
2191
2200
if (InterfaceButton ((Rectangle ){ layoutRect .x + layoutRect .width - 30 , layoutRect .y + 4 , 22 , 22 }, "X" ))
2192
2201
{
2193
2202
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 );
2204
2204
}
2205
2205
}
2206
2206
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)
2549
2549
// Initialization
2550
2550
//--------------------------------------------------------------------------------------
2551
2551
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 " );
2553
2553
iconTex = LoadTexture (WINDOW_ICON );
2554
2554
2555
2555
// Load resources
2556
2556
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
+
2558
2562
visorTarget = LoadRenderTexture (screenSize .x /4 , screenSize .y /4 );
2559
2563
gridTarget = LoadRenderTexture (screenSize .x , screenSize .y );
2560
2564
fxaa = LoadShader (FXAA_VERTEX , FXAA_FRAGMENT );
@@ -2577,7 +2581,6 @@ int main(void)
2577
2581
UpdateCamera (& camera3d );
2578
2582
2579
2583
SetTargetFPS (60 );
2580
- SetLineWidth (3 );
2581
2584
//--------------------------------------------------------------------------------------
2582
2585
2583
2586
// Main game loop
@@ -2624,7 +2627,8 @@ int main(void)
2624
2627
DrawInterface ();
2625
2628
}
2626
2629
2627
- if (drawVisor ) DrawVisor ();
2630
+ if (drawVisor )
2631
+ DrawVisor ();
2628
2632
2629
2633
EndDrawing ();
2630
2634
//----------------------------------------------------------------------------------
0 commit comments