Image: https://www.bitcot.com/flask-vs-django/ Breakdown I had experience building with Python and other APIs, but I’d never worked with a web framework. I wanted to learn how a full-stack web application fits together, so I learned two of the most popular Python ones: Flask first, as the small and simple option, then Django, as the larger one with more built in. This post breaks down what I learned from each, and how they compare. Tools Python 3.14 VS Code Virtual Environments Flask Django The Use Cases For Each Flask Built for simple projects, with a small core and a minimal set of features. Easy to install and quick to get started with. Fast and lightweight, but not designed for high-workload projects. Built on a synchronous model, so each worker handles one request at a time. Handling several requests at once means running multiple workers or threads. Best for quick projects and prototyping, like getting a ...
Back In 2023 I started writing shaders on ShaderToy to better understand the GPU pipeline & how things render on screen. I got some cool results, grasped the fundamentals of GLSL and learned some graphics programming principles. Only had two problems though, GLSL didn't feel modern and it felt like my work was stuck on ShaderToy. What do I do now? Well, modern engines use HLSL, and GLSL and HLSL share a lot of commonalities in what they do, while having a few differences like data types, functions & entry points. The structure exists, all I needed to do was make it run in unreal engine. Should be easy enough, right?
The Problem
Data Types, Variables & Functions
The very first step was to convert all the data types & variables, in VS Code, then pasting code in the custom node and intentionally get errors. I figured, if I break it, then I know everything wrong with it and what to debug. If I don't know what an error means, I get to learn that too. A little brute force-ish? Maybe, but I know what to look for now. Big brain. The conversions were as follows:
vec2 => float2
vec3 => float3
vec4 => vec4
iTime => Time
iResolution => Resolution
fract => frac
Entry Points
Next, I removed main () function & it's global variables. All GLSL shaders had void mainImage( out vec4 fragColor, in vec2 fragCoord). All I needed to do, was get rid of that, fix my indentation, then let Unreal Engine handle that by creating nodes for those variables and connect them to the custom node. I also then defined all the variables within the main () function their respective nodes. All the important nodes are as follows:
TexCoord - To define the UV coordinates. These were then multiplied with a scalar and then added, so I could manipulate the shader look.
float2 - To define the 0 to 1 U and V space.
float3 - To define the colour.
Time - To define the animation over time.
#define macro
This was the first time I had ever encountered a #define macro, more specifically, Function-Like macros. What are Function-Like macros? Well, these work like normal functions and accept relevant parameters. They can only work when the arguments follow the macro name in parenthesis. This makes it one single line of legible code. Macros play really nice with custom nodes, instead of having 2 different custom nodes containing functions & the main body, respectively.
#define macros are an easier way to wrap a function into a simple, readable single line of code. Understanding order of operations in macros is very important for translation. Macros are much more reliable when working with custom nodes.
Avoid naming variables similar to built-in HLSL functions. Lastly, knowing the difference between how data types & functions are handled between GLSL & HLSL is very important, especially for main () functions & global variables.
Additional Shaders
Conclusion
Surprisingly, it was a bit easier than the assumed difficulty. The biggest lesson was learning how to work with a #define macro, as it was a great way to simplify functions into one line for readability. Having a surface level understanding of C/C++, it was definitely a new concept. Not too bad of an experience.
Final code
#define sdSphere(p, s) (length(p) - s)
#define sdBox(p, b) (length(max(abs(p)-b, 0.0)) + min(max((abs(p)-b).x, max((abs(p)-b).y, (abs(p)-b).z)), 0.0))
Comments
Post a Comment