Coming from Unity & heavily into custom shaders, is UE4 for me?

Hey folks,

just downloaded UE4 and gonna give it a spin now. But also want to gather some in-depth feedback regarding some of my use-cases/topics I implemented very nicely in Unity 4.x previously writing custom shaders.

Main reasons I’m now looking into UE4: it’s C+±based, has a better performance reputation, not outdated Mono Framework / GC to fight, seemingly much better editor performance, more robust and contemporary terrain. But – one of Unity’s “pros” is the render pipeline is quite transparent and fairly “hackable”. Implemented various physical-based shading algos in Cg smoothly and really like to handcode shaders knowing the project context and rendering requirements.

By the way, I know “UE is full source so you can tweak it any which way you want” but this is unrealistic, I want to ideally stay within the official engine version to allow for smooth future updates, want to minimize the time spent hacking C++, etc… so in this thread looking for current or potential/near-future out-of-box support :smiley:

Custom deferred

One thing I implemented was “my own deferred renderpath” setting up multiple-render-targets with specified render-texture formats, ie. my own g-buffers to be sampled into from inside my own custom-coded post-process “lighting (and lots of other PP) Cg shader”.

Did this originally because Unity 4.x Deferred is 2-pass (light pre-pass) and I desired single-pass (more modern deferred like UE also uses). But quickly realized it’s very powerful if I can control which g-buffers exist and what info they encode. Lets me later add support for per-pixel wetness or motion-blur velocity or or or… you get the idea. Applying physically-based lighting for diffuse+specular+reflection in a post-shader is a comparatively trivial matter for me now. The question is whether I can set up something similar in UE4 using its existing API without rewriting a lot in C++, because for that I wouldn’t be cut out and would be counterproductive.

Post-process shaders

I know the most-important common post-processing effects are included out-of-box but there’s always scope for more, heat-waves etc! More importantly, I really prefer to read and write the shader code that’ll run. In Unity if you select multiple out-of-box post-effects, they chain them so each is its own render-texture and shader program invocation. Wasteful. I combined all I needed into a single post shader. So all in all have 2 post-processes, lighting itself (plus a few effects that use the depth and lighting info already present at that stage, including some stunning “water as a post-process” shading) and final (other trivial stuff like natural-bloom, tonemapping, underwater, color corrections). Will I be able to “hack it” similarly in UE4? Or how do multiple post-effects get combined here? Where’s the “shading internals” documentation? :smiley:

“Realtime IBL”

In this project there’s never be any baking or lightmaps. All lightsources are movable and dynamic, think open-world 24-hour cycle. I faked “realtime IBL” for a beautiful ambient term by generating per every (or every nth) frame a simplified reflection texture (sky and terrain and big static geometry vertex-lit), supporting both HDR cubemap and 2D HDR paraboloid. Performance-wise fine, no bad hit, shader code as usual under my full control. This gave me “skylight” of sorts and an ambient term AND per-pixel reflection color that was really fairly pretty when also doing physically-based shading. “Good enough, given that we don’t need to bake or preprocess anything ever for it.” So much so I wouldn’t even worry about any indirect lighting / global illumination as long as some ambient-occlusion happens later on. Now, once again the question: does UE4 something similar out-of-box, will it in the near-future, or can I implement this myself in a reasonable manner?

Vertex shaders

Sooner or later you need them. Can I code them for UE4 as part of materials? Funkiest vertex-shader thing I did in Cg for Unity was Morgan McGuire’s single-drawcall terrain renderer

Look forward to all your opinions on any of the above :smiley:

Not quite Cg, but the material “custom” node allows you to implement your own HLSL code.
Its alittle bit awkward at the moment as you have only one input line in the details panel.
Just type the code in notepad and copy it into the field. Dont worry, it willl fit :slight_smile:
But Im afraid you will have no information about lightsources within materials…(correct me if im wrong)…

Cheers,
Klaus

Cheers Klaus! Gonna have to look into that, HLSL is as fine for me as Cg or GLSL :wink:

Now that is kinda weird :smiley:

Most likely not since UE4 is all deferred, but that’s cool.

BTW I did find the Shader Dev page by now… still reads strangely cryptic to me right now but probably a matter of getting into “the UE4 way” of thinking…

Also noticed something built-into the sample projects called a “Skylight” but impossible to tell if that only works as pre-baked lighting or also dynamically (if so, how, as spherical harmonics or what…) it’s all a bit black-boxy right now for me :confused:

You can feed the light vector to the material via blueprints.

And Skylight is a beautiful thing. You can use it both for static and dynamic lighting. If you use captured scene it gives you ambient lighting depending on the overall lighting of the level, or you can import an HDR image as a cubemap and get custom lighting. You can even lit your level with only an atmospheric fog and a Skylight without the need for a directional light and it can give pretty good results depending on your needs.

:wink: I can see that Skylight is at least as pretty as my own hacky Unity concoction but still wonder what’s happening effectively at runtime (when all static lighting / baking is disabled), does it render into a cubemap render-texture every frame (and if so, is that reused for reflections), does it calculate spherical-harmonic coefficients (to save both all the render-to-cubemap cost and the cubemap sampling) to feed into the lighting shader, or … :wink: I guess I’ll be able to find out in the docs, first it seems I’ll have to view the 100s of official tutorials videos to really get into the groove of this engine

From what I understand, skylights only add color to the overall scene. I’m not entirely sure about this, but my method was to just raise the environment color in lightmass to the sky color, which illuminates shadowed areas and bakes the result directly into the lightmaps (which need to be baked anyways) without adding anything to the runtime cost (not that it would be much, but still). Also, I heard skylights will basically destroy your contrast and should generally be avoided if you’re going for a more realistic look.

OK, I went in my project and messed with a few settings, and it seems skylights are WAY more important to UE4 than UE3. In UE4, skylights fill in reflection data that would otherwise be missed by the screen space reflections: the sky and ambient lighting all around. It can take any cubemap, or function as a basic reflection capture. I recommend keeping it on as a stationary light, as static lighting fails to fill in missing reflection data. For some reason, even sphere reflection captures don’t pick up the sky, so it’s really important to have one in on stationary mode.

Keep in mind that you must make it movable if you are using dynamic lighting.

OK cool so ‘Skylight’ seems to implement what I called “realtime fake IBL”, good stuff. Still slightly miffed there’s no way to quickly write out blueprint scripts and material shaders in some code form, all this clickery is gonna drive me mad I fear and having 4-6 fat nodes hanging around for what would be a 1-2 liner will require some getting used to – but the Unreal Editor is so rock-solid, sturdy and stable it’s simply “unreal”, coming from Unity :smiley:

Links to shader development seem to be offline at the moment - or permanently broken?

Indeed a lot of links I was reading yesterday seemed to have vanished today.

This link in the pinned reference section looked perfect, called “Creating Materials and Shaders”

But no longer links.

I hope this is just a temporary issue.