Saturday, November 4, 2017

Substance Designer / Painter, part 3/3

Almost forgot. Had to finish up the series of Substance posts. My head always flies in all directions. Programming A.I. in Tower22 on Monday, overwork on Tuesday, making shampoo bottles in 3D on Wednesday, beating Red Alert on Thursday, saving the world on Friday, playing as architect for our new house on Saturday, and fooling around with Substance Painter on Sunday. It's not necessarily that I'm a busy man, I just forget what I did today, and start somewhere completely else tomorrow. Like my great-grandmother.

That makes it hard to *finish* things for once. Being a programmer, my whole life feels a bit unfinished anyway, as software/code is typically never done. Not at work, not for Tower22. How nice would it be to do something, finish it, then sit down and treat yourself with a beer? Not for me, there is always some work that needs attention. This Never Ending Story makes me restless. Good thing that I forget and switch tasks though, otherwise it would feel as a very, very long, dreadful trip.

So usually my 3D assets would feel half-finished as well. Starting a room or 3D shampoo bottle with a fresh spirit, but then quickly rushing it the next day as mountains of other work are still waiting as well. Making a model is usually not that hard (for architecture or basic shapes). But the devil is in details - texturing details mostly.

 So much work... For a patch of rust.

Stupid textures
When I started hobbying with 3D, somewhere around 2002, you could get away with a MS Paint drawing. Or as I did, print the UV-map lines on paper, then paint literally on paper, and scan them back in. And that was that, kick-ass. Ok, the seams sucked a bit, but who cared. A 256 x 256 resolution would "mask" such buggers anyway.

But then bumpMaps came. And specular or glossMaps (till this day I still don't know what the exact difference is). Generating such a bumpMap *correctly* would mean loads of extra work, as you either need to make the same model in super-detail first, or draw heightMaps carefully and convert them. Yes I could "draw" bumpMaps, and having the illusion of extra detail was kinda cool, but often the quality was poor and lacking time to put all that extra effort in a fucking 3D shampoo bottle, I usually skipped them.

And then it got even worse, with PBR - Physically Based Rendering. Well, not worse maybe as the industry standardized all those crazy tricks and shading hacks into a more universal set of textures, giving measurable results with input data based on actual numbers. But... how the hell do I know the exact albedo and roughness values for a sewer-sludge texture? Got to grab the physics books and calculate the IOR (Index of Reflection) for foamy slime and turds with peanuts. 

Needless to say, I didn't do that. Resulting in PIR - Physical Incorrect Rendering. God, where are those good old days of just drawing something on paper? For one of my first more serious (2D) games, I made photos of clay animated figures! Quick results & a lot of fun. And look at me now. Stuck somewhere between the PBR world, and the Dark Pixelated Side of Indy games that just say "Screw it. Throw away all fancy graphics and join the Pixel". 

Now I'm very curious what you boys & girls think about the picture above. Because T22 is basically tumbling on a graphics edge; if I want to stick with "High-Def" graphics, I need a lot of help from expert artists... The alternative is to simplify (not necessarily uglify) the graphics, which allows "lesser-quality assets" to join the game. Obviously a far more realistic path, but it feels so unnatural to spend a billion man-hours into advanced graphics, and then just drop it. Then again, as a wise man named Marcellus Wallace once said: Fuck pride.

I'm still undecided. BUT, at least the Good Graphics(tm) side sent in some reinforcements; Substance Painter. A 3D Painting program.

Substance Painter
The concept of 3D painting is nothing new. I remember doing that back in the print & scan oil-painted texture days. Also remember I wasn't very pleased with it. Yes the edge problem was sort of solved, and what you see is what you get. But the painting tools were very primitive, compared with programs like Photoshop. It... it... it just sucked.

10+ years I'm trying again, and with an inner smile this time. First of all, the navigation, brushes and painting tools all feel much better. I felt something I didn't feel for quite a while, wrestling with old fashioned tools to create unfinished C-rated quality assets. I felt FUN. It was nice to doodle, and see pretty darn good results right away.

The most importance trick that Substance Painter has in its sleeve, is that it generates multiple textures simultaneously, with PBR parameters if you like. If you paint gold, you really paint gold. Not just some brown-yellow colour, but also the corresponding "Metalness" value, Roughness/Smoothess, and eventually a micro structure that represents gold. Now gold is smooth typically, but you could also draw concrete or denim-cotton. As you paint, also the height- and/or normalMaps take over the exact same patterns. This leads to *correct* textures, without too much extra effort.
A lot to click, and I'm unpatient when it comes to learning new things. But it works pretty simple, and otherwise there are tons of tutorials, like the (Spanish) one above.

Besides the "Substance Share", where you can download/upload loads of extra brushes, materials, presets and effects, there is not too much else I can tell about it, as my trial version expired and the package is just what it is - a 3D painter. But as said, a very nice one. What matters in the end are the results. Without too much effort, I created a texture that was better than anything else I tried before, the old-skool way (in my even older Paint Shop Pro version 5). Including a proper roughness and normalMap. And a baby-smile on my face. Priceless.
Being able to generate higher quality stuff myself once again, pulls me a bit back towards the "Advanced Graphics" side, as T22 was once intended. Whether a horror game like this truly needs tiny rusty speckles and 2048k textures for a bucket of vomit is another discussion though.

Saturday, September 30, 2017

Substance Designer / Painter, part 2/3

That was a pretty good sales pitch right? That previous post, being all emotional and unsuccessful, until I discovered Substance Designer and Painter. But in all seriousness, this was just what I needed to boost my lacking 2D-Texture skills, and more important, to bring back some joy. Being proud again. “Look dad! I made a rusty pipe texture!”.
"Look mom! I made a white/orange-pinkish dirty painted wall!"

I’m not sure how long these “Substance” programs have been around, but at least I never heard of them until I came across an interview with an Environment Artist veteran, who wished he had learned to work with more modern software like this earlier on. Got stuck in old habits while those damn kids from the neighbours passed by on their fancy turbo-roller-skate-future-things. Environment Artist? Check? Tired of traditional workflows? Check. Sounds like me, goofing around without too much success in Paint Shop Pro and Lightwave for many years. Except that this guy was much better, and found solutions.

So, being triggered, I gave it a try but didn’t expect too much. You know, at some point you get rusty and prefer to stick with whatever techniques you learned. If you program Delphi for 20 years, it sucks to restart and having to learn everything from scratch again in another language. Nonetheless, such “escapades” can be eye-openers. Not often, but sometimes, sometimes it’s like love on first sight.

I had that with Sculptris some years ago. After playing with primitive cubes and cylinders like a baby in “normal modelling software”, who would have thought I could make a one-million-poly organic thing that actually kinda looked like a humanoid? Malformed and monstrous though, but that was the assignment after all. Using Sculptris was a revelation in two ways. First because I succeeded for a first time, second because it worked completely different than any other 3D modeller I had seen so far. Even the UI was completely different… Awkward I’d say, even a simple task like Saving required a cold brain-reboot with Sculptris. It’s as if that program wasn’t made for a Windows computer, but for some unknown alien OS. Normally I would give up fast on weird programs, but “digital claying” was so much fun. And once you know the weird spots and hotkeys, it works pretty simple actually.

Now I had this same kind of experience with Substance Designer. While downloading the trial, I watched some YouTube movies. Results were very promising, but the way of working was… nothing like Photoshop (or Paint Shop Pro in my case, I just grew up with that – and probably missed a whole lot of 21th century 2D-witchcraft, still using a very old version of that). How to explain it… have you ever watched a 64K demo??
Sometimes you fall in love... with strange programs. Like Substance Designer.

64K madness
64K demo is just a program where a camera flies through a, often abstract / Sci-Fi themed, world. Complete with 3D stuff, animations, particles, and a layer of audio on top. All pretty normal, but there is a small catch; as the name suggests, the BIG challenge is to put the ENTIRE program into TINY 64 kilobyte storage memory…

We all know you’ll have to feed a game engine textures, 3D geometry and audio waves. Otherwise it won’t poop out anything. Typically these resources are packed in ready-to-rumble files, like TV dinner lasagne. You would draw textures with a digital brush and photograph snippets. You would model 3D geometry with primitive shapes and triangles, dragging their corner vertices into the right positions. You would make audio by recording samples and mixing them together. All “pre-processing” work.

But a 64K demo doesn’t use any pre-processed files. Just generate an empty 256x256 pixel bitmap in MS Paint, and you’ll notice you already exceeded the limit, 3 times! In a 64K demo, everything happens at the fly. Textures, geometry and audio are computed mathematically. Bubutbut, how?!
You could make a shader that generates random pixel colours, but that would result in total chaos and epileptic attacks. 

There need to be certain patterns. Patterns you can describe in a mathematical way. Math and natural, organic creations sounds like an unhappy match, but if you believe in a God, he or she must be the greatest mathematician of all times. Mountains or ocean waves, they can be simulated using sines, Fourier transformations, and a proper set of input constants. Bathroom or pavement tiles have rectangular shapes. Rust, mould and moss starts in gaps, and grows in certain patterns. Trees turns into grass, grass into rock, and rock into snow as we climb higher on a mountain. Wind blows in a certain direction.

Think in (noisy) patterns
Nothing happens just randomly in nature. And by observing, you can translate that “behaviour” into formula’s, choices or semi-random noise that delivers values between certain constraints. Everything you see and hear in a 64K demo is based on that, and thus computed real-time. Substance Designer borrows some of that principles. You won’t be drawing tile lines, skin pimples and rust layers here. You’ll be calculating it.
Here the very first to compute a wood nerve pattern (thank you Daniel J.R. for showing how!). Banding is created with a gradient, horizontal blinds, and perlin noise. Next this banding gets warped semi randomly, based on another perlin noise. The result (below) looks trippy, but hey, ever looked close to a plank while being on drugs?

Substance Designer is a texture “composer”, “calculator”… I’m not sure how to call the process, but you won’t be drawing, that’s for sure (though you can import photos or handmade textures and throw them into the formula). You’ll be connecting various “base patterns”, noises and mathematical operators such as blends, contrasts, warps or high-pass filters. Sounds very hard, but the node-based system allows a fast trial & error approach. Just connect X and Y, and see what happens. Soon enough you’ll be generating useful patterns that can be used in your material, or otherwise in a future one, as you can build your own library easily. So, no, you really don't have to be a scientist to use this.

The results can be converted to typical (PBR) textures in the end. In a lot of cases you’ll be making masks and a heightmap first. That heightmap can be converted to a NormalMap and AmbientOcclusionMap. But the bumpiness can also tell something about the roughness/glossiness. Sub-computations can be linked to other sections that generate dirt, damaged edges, rust or whatsoever.
No you understand what the trippy pattern in the picture above is doing. It is used is used to generate colors, but also has a subtle effect on the NormalMap and RoughnessMap.

But is it useful?

Now I can hear you think... that floor above sucks, and also, I can do that in Photoshop just as well - and probably a lot quicker. I doubt if SD is any faster than a good old paint program indeed. It took me hours to generate the texture above, and yeah, the saturated colours are a bit weird. In my defence, a horror game needs weird textures. But more honestly, of course I lack skill (and patience). Just check YouTube, and you'll see some truly amazing (and very informative) results.

If you master the brush, I bet you can do the same -and (much) quicker. But at some point, SD takes over the torch when it comes to micro-detail, *correct* results, and making tweaks afterwards. Let me explain.

One major power of the Substance Designer workflow is that the various output maps keep a correct relation with each other. If you want to change a texture-set generated with Photoshop, you'll typically have to break-out certain parts, and redo multiple layers. In SD, the entire graph automatically adapts when changing a formula or input pattern. This allows to quickly experiment with different settings, and to generate multiple output variants (see the wall-paint texture below).

On the longer term, this will gain speed. And as said, every change is done correctly. Adding a tiny speckle will not only update the colors, but also the normals, height, metalness, roughness, occlusion, and so on. Also, if we decide the texture resolution is too small, we can increase the whole damn thing with a few clicks. Not just a cheap upscale operation; as with Vector based graphics, the actual detail and variation will increase. And... all done seamless of course.

 Making the dirty variant of the wall texture was pretty easy once the base graph was made. With Vertex-Painting you can mix these two textures in the engine.

I can do it
Maybe most important, for me at least, is that I could make these textures in the first place. It took some time, patience and copying ideas from YouTube tutorials, but the results were better than any other texture I ever generated. And that is what counts, right?

I could copy realistic photo snippets and smear some poop dirt in a layer on top. But making (correct) normalMaps or turning them seamless without a cheap lossy approach was beyond my Harry Potter powers. So yeah, I'm quite happy :) Of course I still need some true artists to turn the Tower22 demo into something beautiful, but at least Substance Designer gave me some tools to do it myself again, for the time being... and for as long the trial version still works that is ;)