Shaders

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

  1. Not knowing why some material nodes are red.

  2. 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.

1 Like

Exactly what I eventually ‘intuited’ :joy:

Lovely explanation, btw.