How do I understand how shaders work? So I can code shaders without questioning what each function is doing, like scenetexture: blank, texcoord[num], Absolute world position, how data works in shaders, etc, etc
Of course you have the palette which is a bit list of all nodes sorted by category. But thatâs not much help. If you ever find a vid about this, Iâd love to see it. Trouble is, I donât think there is one.
I remember the two most frustrating things when I was learning UE were
-
Not knowing why some material nodes are red.
-
Not understanding how vectors can be a location and a direction.
Iâve never seen anyone explain either, in any depth. They just start wiring things up and you have to copy it ( initially ).
How a vector can be a location is obvious, how it is a direction is sort of implied if you understand it started at the origin ( or pivot of the object is weâre talking local space ).
I still have no idea about 1, but sort of understand it intuitively.
Generally speaking a Shader is the actual code/script/mini-program that is handed to the GPU hardware. Each GPU manufacturer can have its own implementation of these shaders, and sometimes the API runtime can have its own expectations/requirements for shaders (this is most meaningful in web-dev where sometimes a different Browser, Runtime, Hardware, and in rare cases Operating System can have different expectations about a shader). Basically if you wanted to learn about every version of shader that is a lot of combinations of documentation (which all of these are documented like AMD, NVidea, and Intel all have rather extensive documentation on shader code being passed to the driver).
technically it is web-dev that still needs to worry the most about manually coding shaders mostly because many other applications of shaders have made a large attempt to abstract away the most frustrating portions of shaders like matrices, and the linear-Algebra/Calculus portions.
with regards to Unreal A shader
is the internal derived version of your materiel blueprints.
in some ways Unreal is borrowing the term because Unreal Shaders are designed to be âas hardware agnostic as possibleâ so that we donât have 3-5 different versions of each âshader assetâ per material so technically 6-10 script files per material (I am kind of cheating and lowering the number here as really each material would generate 1 Shader script the code that is being run, and 1 shader object which is the Vertices and UVs of the given mesh that is unique to that Mesh; so a cube and a cone will have the same Shader script, but 2 different Shader Objects). then when we go to Cooking/Packaging for the specific hardware we are targeting Unreal will then create the finalized shader script for that platform (everything besides PC/Linux will have 1 shader pair per material, where PC/Linux needs to account for at least the 3 hardware manufacturers)
for Material blueprints if you are wondering what each node color means:
-Silver/Grey: this is the final output result of the material (some systems will call this a âPrinciple shaderâ or some acronym that I canât remember many of them)
-Grean: these are either constant/const integral/âscalarâ data (mostly floats, and sometimes integers), or a âmany to oneâ math operations (these are expected to have consistent/constant output per UV iteration so in those cases they are soft cached in the shader script)
-Gold/Bronze: these are mostly Vector constants (Vector2 which would be for a UV, Vector3 which can be used for position, direction, or non-alpha color, or Vector4 for Alpha-color)
-Light Blue: these are functions defined in the Engine through blueprints (double click and you will be taken to the material function that is being performed)
-Dark Blue: these are struct objects for the shader
-Red: these are source defined functions/scripts that are very likely to be hardware dependent, and will work with the shader Object while it is living on the GPU; either the variables of the script, or the Meshâs data. Many of these actually have a secret input of the Mesh, or the Meshâs UVs.
_ Red could also be âinput to a functionâ (at which point for comparison to the previous would be âit comes from somewhere elseâ in the most helpful meaning)
for âwhat each node doesâ for this you can hover over it and then hold the âadditional node info for blueprint editor keysâ (ctrl+alt by default) and because Epic doesnât modify these âmuchâ most of them have hyperlinks to the documentation specifically explaining the node. Considering that Unrealâs first implemented of blueprints/Kismet was the Material system back in UDK as a âartists donât need to worry about the hard math and programmingâ the documentation for them is some of the most complete.
Exactly what I eventually âintuitedâ
Lovely explanation, btw.