Tumgik
td-randomstuff · 4 years
Text
Evaluation - What a crazy Half Term
Tumblr media
What Went Well:
This half term has honestly been amazing, i’ve been able to touch on so many concepts i’d never thought i’d use or learn, all while remaining true to the purpose of my project. “To explore the Biomes Of Randomness”.
I started this project with little hope i’d be able to achieve much, time after time again coming across barriers and barracades, slowly but surely making progress. My first successful procedural terrain experiment utilised a procedural randomness plugin that offered a whole host of tools and types of random, including my personal faviourite, perlin noise.
Tumblr media
When this first experiment was complete I couldn’t make a world any larger than 100 by 100 but by the end; After having experimented with lots of other systems, learning as I went I managed to create a huge 1000 x 1000 (and larger world) with seamingly little performance cost as well as fix threading issues amongst others: First breaking it into chunks, then using Event Tick and finally using Proper Threading.
What Could Have Been Better:
While I achieved a lot and it fit under the umbrella of work I’d set myself and the college set me. I wish i’d gotten a more succsinced final project, where I could combine all the different systems I built and skills I learnt into a final presentable project which stands up by itself.
What Would you do differently:
A lot, frankly. While researching is an important part of the process and I would never have gotten anywhere without trying 100 different techniques to find the one that works. I wish, earlier on, I’d decided found a viable method and stuck to it and built off it.
In my next project as we take a look at story driven games I hope to create a more streamlined vision that by the end is more presentable and focussed.
0 notes
td-randomstuff · 4 years
Text
ART | Code & Design
Art
Tumblr media
The first thing you have to do with any project is decide how you want it to look and feel. As I wanted to do a lot of quick prototyping I decided to use a mat, low poly design that wasn’t overly sylised but looked easy on the eyes.
Vagually relating to Sebastians procedural terrain series and No Mans sky, the later of which was a huge art style goal that I sadly wasn’t able to live up to.
Code
Tumblr media
Code was the main focus of my project, writing lots of little systems relating to: _Procedural world and object generation in relation to Randomness. _
I used code (in some form) for every single part of my project from counting the number of trees that got displayed on some UI (through some event binding) to generating a heightmap for the entire world to writing Shaders in C++ with the assistance of the material editor or a multi threading wrapper in C++ that I could then access via blueprint.
I really used it for everything and what a painful joy it was.
Design
While it wasn't the focus of my project, I spent some time thinking about and creating a rewarding gameplay loop that allows you to fly around the world, fly through hoops as the randomly spawn over the terrain and explode when passed through (destructable mesh with plugin).
There by creating a somewhat rewarding and never ending gameplay loop that shows off the main focus of my project.
0 notes
td-randomstuff · 4 years
Text
Alternatives to my Tree System
Unreal Engine also supports a variety of out of the box solutions for foliage for thingsl ike grass, to trees and shrubbery. Even creating Procedural/Random Versions.
Tumblr media
With the Procedural Foliage Spawner, it works much like InstancedStaticMeshes but with a lot of the heavy lifting done for you. All you need to do is tell it a mesh and seed number, let it handle the rest:
Tumblr media
0 notes
td-randomstuff · 4 years
Text
My Tree System in action
youtube
Using a combination of Raycasting, Instancing and GPU optimization i can render up to 500 thousand objects in the scene at once, and 150 thousand with no noticable lag, this is all done randomly but with checks to make sure they’re not overlapping (We don’t want a leaning tower of trees).
Tumblr media
As you can somewhat see in the above clip we’re also spawning in destructable rings which explode when you pass through them in the players ship, this way adding a little bit of gameplay to an otherwise experimentational project full of little (and big) tests.
Tumblr media
0 notes
td-randomstuff · 4 years
Text
The painful journey of modifying UE4 source code.
I knew if I wanted to use Unreals Engines Height map nodes in relation to landscapes I’d need to modify ue4s source code as explained in this forum:
https://forums.unrealengine.com/community/community-content-tools-and-tutorials/1557162-blueprint-powered-procedural-terrain-generation-is-now-possible-in-ue4-4-20
First & Second Attempt
At first I attempted to modify the related file straight from ue4 directory to no evail - it had no affect in editor, as if nothing had happened.
Then I decided to download the source onto my SSD from Github (which requires you to jump through some authentication hoops to gain access to the repo). Having done so I followed the setup instructions, carefully unloading the related assets through the console.
ERROR - Once Visual Studio 2017 was open (which was difficult to get open in it’s own right - getting a dialog window saying “trial expired). All the repositories systems had failed to compile.
[At this point i’d spent about 2 and a half days on it.]
Third and Final Attempts
Deciding to take the work home, I started affresh, going through the same steps, it'd appear the earlier two problems were due to college firewall restrictions which stopped me from downloading and running all the necessary code.
Finally it compliled, Great time to fix this code, create a copy of "LandscapeImportHeightmapFromRenderTarget" with a slightly differen name and outside the "#if with_editor' statement so it's exposed (as well as removing or disabling: UnsafeDuringActorConstruction"
Let's compile (another hour passes) - ERROR ERROR everywhere. If you compile the engine incorrectly or mispell anything the whole hour is wasted. This happened more time than i'd like to admit before it worked.
0 notes
td-randomstuff · 4 years
Text
Inspiration: Sebastian Lague
Tumblr media
Several Weeks back I was alerted to the existance of Sebastian Lague’s youtube channel by a collegue at work, his series on world generation. And while I’d already settled on what to do, he was a great inspiration for tackling theoretically difficult areas of game development, head on.
Giving me the confidence to attempt to write shaders, modify Geometry and Unreal Engine Source Code (Which is covered in a different post).
Sebastian develops games within Unity so I couldn’t copy and paste any ideas but I could learn from the fundementals in his videos and apply them to my own project in ue4.
0 notes
td-randomstuff · 4 years
Text
Insipration: Horizen Dawn
I’ve talked a lot about Horizen Dawn in this blog already as it was one of the main reasons I was so interested in exploring shaders, Having watched their GDC talk I was amazed by just how much is possible with such limited code.
youtube
I knew I couldn’t replicate anything near what they could do but I certainly wanted to dip my toe into the water and see what working with shaders is like.
youtube
I was first captivised by their “ GPU-Based Run-Time Procedural Placement in Horizon: Zero Dawn” presentation but settled on trying to replicate some of the Vegitation which went extremely successfully, with GPU optimization but without actually touching Shaders, as such I decided to explore shaders in another corner of my project, Terrain Blending.
0 notes
td-randomstuff · 4 years
Text
Inspiration: No Mans Sky
One of the earliest inspirations for this project was No Mans Sky, while the game itself may have been a bit of a disappointment, the actual maths behind it is anything but.
youtube
I’m also I a huge fan of the art style used and was happy that I was able to somewhat replicate it, starting from blockly minecraft like blocks to smooth terrain. I also experimented with creating little worlds using Noise to some success:
Tumblr media Tumblr media
0 notes
td-randomstuff · 4 years
Text
Modifying Meshs via Shader
Unreal Engines Texture Editor is in itself a simplified shader by definition and we can actually modify the attached mesh through them using the “WorldPositionOffset” input. Combining this with a simple gradient & panner for movement can have some really wacky results:
Tumblr media
This is something I hope to expand on to fix the issues related to normal maps that broke the “Blop” effect between Spheres but in early testing there seems to be some conflict with using Vectors (CameraVector,SceneDepth etc.)
Tumblr media
The code for the above gif can be found below:
Tumblr media
0 notes
td-randomstuff · 4 years
Text
Playing with Textures
Now that my world was all set up and I had a few successful experiments and a hanful of not so successful I thought I’d take some time to create a nice water texture I could place at the base of the terrain.
To do this I used the world position as a foundation to create a panner with a speed to move the water. At first this had some odd results with the water moving with the camera but I soon got this fixed.
Tumblr media
I then use NOISE, still a random based project, with the lerp node to blend the two together. Initially I tried to use the lerp node to move the water as i’m used to lerps relating to tweening but got that wrong. This had, what I consider, a suprisingly nice result although I’d love to add in some height data in the future.
0 notes
td-randomstuff · 4 years
Text
Blop Shader, Issue
While I felt very accomplished getting the shader finished, this was soon lost once it interacted with shapes with the same material, as they’d constantly try and overlap each other.
Tumblr media
This was something I had no accounted for as I at the time of making I wasn’t aware that I wasn’t modifying the mesh, just it’s normal map. Therefore it can’t detect the object’s shape correctly as only the normal maps been distorted.
A possible alternative solution to the original problem were “Procedural Mesh” objects, something I only discovered at the end of my project.
0 notes
td-randomstuff · 4 years
Text
Raymarching Blop Shader - Material Editor
The main purpose of the material editor for our shader is to supply all the releavant values for our shader code. This includes:
Max Steps - Number of steps to iterate for
CameraVector - Vector Direction to calculate from
WorldPosition - Position in the world
ObjectPosition - Local position (both used for calculating distance)
SceneDepth - As we’re working in 3D
CameraPosition - The position of the ray start
Smooth - int for smoothing.
Tumblr media
We then take the RGBA output, split it to use the mask for opacity, without which the effect is broken as the hidden shape volume is visible and second the normal map so we can manipulate how the material appears.
Tumblr media
0 notes
td-randomstuff · 4 years
Text
Raymarching Blop Shader - Code
Unreal Engine typically connects with Visual Studio for a steady workflow but I decided to use VSCode, my go to IDE set up with my favourite plugins which slowed down my workflow slightly but is super easy to work in.
Tumblr media
Raymarching requires us to "step” into each volume so to start off we need to create a loop with “MaxSteps” to loop through. We’re going to be working with “Signaled Distance Functions” (SDF) for short, in fact the simplest of which, a sphere.
We also need to reference our variables so we can store these in memory if they don’t exist via input (i.e already exposed) or want to rename an exposed like in the case of WorldPosition.
There’s an amazing article on Signaled Distance Functions here: https://medium.com/@si.ashbery/raymarching-3cdf86c637ba
RmSphere(pos - ObjectPosition)
This function takes in the the given position, i.e our WorldPosition - Object Position, and returns the length of said position minus a certain integer, the smaller the number, the smaller the volume.
Tumblr media
We can then compare this number against some small sanity check and if it’s true 1 else 0. Congratulations, you now have the worlds simplist raymarching system.
Tumblr media
In the final system we have built on top of this using smoothing functions found on: https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm that allow us to blend the object; I tried using several different ones till I found the best result.
0 notes
td-randomstuff · 4 years
Text
Raymarching Blop Shader - Research
Going back to my original terrain implementation i’d since built on with the tools and skills i’d learnt I wanted to tackle the last problem now i’d solved:
Loop Issues,
On Mass loading
And High Performance costs leading to small generation areas.
The problem being appearance, each sphere created did not blend into the next, to fix this I decided to look into shaders having heard about an interesting approach to Sebastian Lagues cloud generation using raymarching.
Tumblr media
(Above clip taken from Sebastians YT)
This was exactly what I wanted to achieve, so I got researching. Shaders use C++ (actually HLSL) and my C++ knowledge is, shaky, I studied it for about two weeks over the summer holidays to prepare for this year.
I knew while I can write C++, i’d find it a little much to write an entire shader off the bat on my first go (maybe more than a little much); Thankfully I stumbled across an amazing video
youtube
Which did an amazing job of walking through the process. Sadly they were less good at explaining the why so I had to do some more researching. Luckily they’d included a link to an extremely helpful document which was really helpful at getting my head around the maths:
Tumblr media
And definitely a bookmarable page. The other two extremely helpful ones were “Raymarching for Dummies” by “The Art Of Code”, which really helped..dumb down.. raymarching as well as another of sebastains videos on Raymarching.
youtube
0 notes
td-randomstuff · 4 years
Text
Shader Compiling
When you compile your shader code it compiles into HLSL, which stands for “high level shading language” but is much more low level than C++ which is itself known as mid level.
Tumblr media
Shaders can be optimised heavily simply through code refinments as the least amount of memory allecation and pointers you use per pixel the better.
0 notes
td-randomstuff · 4 years
Text
How to: Material Shaders
All UE4 Shaders must be placed within the engine directory (In File Explorer):
UE_4.25\Engine\Shaders
This exposes it to our Material Editor and allows us to compile and run said code, to do this we must make sure we have our .ush code in a file under here.
.ush stands for “Unreal Shader Format”, all shader code should be written in C++ (via an IDE such as VSCode, VisualStudio or Notepad++). Once your code is written, file extension set and placed under Shaders:
Tumblr media
We can access it from unreal engine, to do so we must place a “Custom Expression” inside our Texture Editor. To do this you must first create a new texture by right clicking within the Content Browser and selecting an ordinary Material Asset:
Tumblr media
Within this asset we can create our Custom Expression by right clicking on within the Material Editor and selecting “Custom”, which, once pressed, allows us to enter our code directory through the #include expression:
Tumblr media
Within this we must also return a value, this can be completely random as it holds no relevance and is overwritten by the shaders return value; You can also change the output type & number of inputs.
Inputs are generally different world positions & vectors that the shader needs to calculate how to manipulate the shader for the player. To add inputs you can click the + button next to “Inputs Array Elements”, this can be any variable type.
Tumblr media
When your code has been written and shader is complete just indent a line to trigger a compile and you should see the above in the stats window. IF your script errors it’ll report what was wrong.
0 notes
td-randomstuff · 4 years
Text
Shaders in UE4
Unreals shader support and especially documentation is much weaker than unity; That said Unreal Engine still supports a variety powerful of shader types that can be used to create any affect under the sun.
Global Shaders
Global Shaders are used for rendering post-process affects that don’t affect geometry or interface with materials. This can be used for pixel shaders etc. and is all written in C++* as are all shaders.
https://www.unrealengine.com/en-US/tech-blog/how-to-add-global-shaders-to-ue4?sessionInvalidated=true
Mesh Shaders
Does this exist? No, Should it? Yes. Why doesn’t it? ¯\_(ツ)_/¯
Tumblr media
In all seriousness the lack of support for simple mesh drawing is astounding; There is a hidden away little explanation on their documentation and it is possible via notes but the lack lustor support via shader was quite frustrating.
Texture Shaders
This, unlike Unity is the most common way of writing shaders, you can create a custom node within the material editor. You can do much of the same things as global shaders but limited to that specific texture; Perfect for special effects on certain objects like portals or selection boxs (ToonShader).
Sources:
https://docs.unrealengine.com/en-US/Engine/Rendering/Materials/ExpressionReference/Custom/index.html
https://forums.unrealengine.com/development-discussion/rendering/68840-writing-shaders-for-ue4-where-do-i-start
https://docs.unrealengine.com/en-US/Programming/Rendering/ShaderDevelopment/index.html
*File type is .usf
0 notes