Sunday, September 06, 2020

Is this progress?

 


Sure, it looks like a broken demo cube program. That's because that's what it is. But it represents me getting back on the bandwagon with this whole hobby of 3D graphics programming when I should be doing something to make myself useful. Today we begin with yet another ground-up rewrite, but this time with Vulkan instead of OpenGL, thanks to a hardware update.

I say today, but this has taken literally a few days short of a month to get to the point, just now, where it displayed anything but a blank window. Just before this, I got it to display a blank window with a dark grey background, and then, the broken cube above. (It's because I got the "stride" wrong in my vertex buffer.)

But in any case, this is my hobby and I will waste my time as I like. Forward!



Saturday, October 26, 2019

Transparent Materials

All the changes I have been making under the hood have started to bear fruit. Aside from the layer mask support in shadows I mentioned earlier, beams and billboards support shadows and transparency, now. And ordinary meshes can be made transparent, including ones with layered materials, just by setting an opacity. (Although, with layered materials I also need to make sure not to layer any properties, like gloss or metallic, that are not supported in the transparent shader.)

The resolution of transparent objects is reduced, and shadows for transparent materials are... a bit ugly. But what can you do? This is almost ten-year-old technology I'm working with. It's still pretty neat.

Tuesday, October 22, 2019

Holey Title, Batman

I have been busily rewriting the entire shader definition system to be more flexible and converting all the existing shaders over to the new system. The end result of all this is... nothing changes.

That's not exactly true. Some new features come out of this, just because a new framework makes them easier to implement. For example, masks selected by a layer selection texture can now cast shadows. There are also a lot less classes and clutter around shadow shaders in general, but that's more difficult to illustrate with an image.

Monday, April 01, 2019

Text Too


I built a framework for cacheing letters, and a bunch of code for getting the positions of individual letters in a typeset string from the OS-level text rendering library (Core Text in OSX). And then I wrote a shader that can be called as something like a particle system, picking out the appropriate character data, placing the quad to render that character, getting the cached texture data for that character and drawing it to the screen.

After that, I refactored the character animation code to use what I had learned about buffer textures, eliminating the limits on joints (skeletal animation, mentioned here but implemented before I restarted this blog, some YouTube posts here and here) and shape keys (see this post), and saving a bunch of memory by compacting shape keys to only store data for vertexes that have useful data. It's all pretty cool but has absolutely no visible effect on the final product. Woo.

Today, I made improvements to the screen-space reflection shader (first implemented two years ago) I had been meaning to make for a long time, which means I'm getting close to the point where I can't avoid working on something new.

Saturday, March 02, 2019

Text


So, more fooling around on things which aren't what I was going to fool around with. I need text for debugging, among other things, so I decided I would "get that out of the way." Turns out, it's a little bit more complicated than that.

But, after some work, I have it more-or-less working. Well, a start of it. One part was just getting characters rendered onto textures. Then, of course, I had to start working on distance fields, because all the kids are talking about distance fields these days. The screen shot below might illustrate why.


The two words are rendered using textures of the same size (about 32 pixels high in total). The top one is anti-aliased text, and the bottom is a distance field. The distance field is generated from anti-aliased text at four times the resolution, and then scaled down. As you can probably see, this produces a nice clear shape even at the relatively low resolution of the final texture. Generating distance fields from anti-aliased text, caching font info, getting text and distance fields added to my material definition formats, that all took a bunch of time.

And I still have to get this text stuff into the UI.

Saturday, January 05, 2019

LODs and Skeletons

This figure is familiar from my earlier implementation of skeletal animations, if anyone was actually reading any of this so that they could actually be familiar with it. It's familiar to me, anyway.

The blue man group member has been washed to reveal an almost flesh-colored putty person. But there's a secret here. This isn't the same model as before, but one I've added a simplified LOD mesh to (in Blender 2.80, by the way, which seems a lot easier to use than 2.79, highly recommended). LOD scales are exaggerated, as usual, so you can see the switch as I move the camera around. The cool thing is that the skeletal animation attached to the original (base) model is automatically hooked up so that it works with other levels of detail. This might sound obvious, but, of course, it takes effort to make things that should work actually work for real.

Next, to check that it also works with shape keys (already implemented, but that just means the bugs are all in place).

Wednesday, January 02, 2019

Loads of LODs

Finally back to doing stuff. Another pile of work went in to doing this thing which should normally be invisible.

In the previous post I showed some automatic LOD generation, which is OK I guess, but doesn't do a great job all the time. For more control, you need to be able to import multiple versions of the same mesh which you have built by hand. The cylinder above is actually three separate objects which were created in Blender and imported from one file. The scales for switching between LODs were assigned automatically (based on the size of the faces in the objects), and are exaggerated here, again, for debugging.

So, that's working. Now just to check it works in concert with some other features, and then I can move on to... other things.

Monday, September 24, 2018

Creepy Purple Head Is Creepy

This took a lot longer than I hoped. This post is about level of detail. That's where you take out some polygons and simplify a shape, usually based on how far away it is from the viewer, to save your graphics card the trouble of calculating things for polygons which are so small they only cover a few pixels or less anyway. I've had spheres doing this in my "engine" for a long time, because for spheres it's relatively easy to calculate the appropriate low(er)-poly mesh or meshes. For general meshes though, the easy approach is to create a mesh for each LOD using external tools or by hand. I was thinking of taking an automatic approach to generating these meshes and calculating the appropriate view distances. This would, in my mind, save me the trouble of having to do this outside the engine and tune each model's selection of meshes. (It would also save me from the problem of how to handle shape keys on lower-poly versions of a mesh, although I'd probably just ignore that.)

So, after finishing up fog and transparency illumination in the last post, I noticed that my sphere LOD scales seemed to be a bit off, so I started debugging. That led to bug fixing, and that led to me starting to implement that auto-LOD-generation that I had been thinking about. Like I said, it turned out to take longer than I had hoped. Part of this was finding some reasonably fast and simple algorithm to implement, and part of it was discovering things like Blender had output a separate vertex for every triangle corner in my mesh, even though most triangles share corners with other triangles. This meant a detour to merge these vertexes so I could do a bit of topology analysis in the algorithm (also incidentally saving a bunch of memory after merging the vertex data, although I guess that's not such a big deal compared to things like texture memory).

The final effect is shown in the video above. It works... Ok? I guess? The effect is exaggerated for testing in the video, and normally the changes are basically invisible. I think simplifying material shaders for distant objects will probably be a bigger win (and I'll see if I can automate that too). But anyway, now you know how I spent the last couple of weeks and why clouds still aren't implemented.

Monday, September 03, 2018

Dramatic Sunset Lighting With Forward Scattering

It sort of has something to do with clouds, honest.

Among a bunch of under the hood fixes and additions over the past little while, I went back to my transparency and fog shaders. Both of these effects reference a 3D texture "illumination map" that I generate in screen space. The illumination map makes it possible for all the lights to at least have some effect on transparent objects, including fog. The original illumination map only holds the response of a directly illuminated sphere to incoming light, summed up for all lights. This would be appropriate for clouds made of fairly large particles, which is why I talked about dust in the description of the first video. Maybe blowing sand would be a better description.


Notice how the transparencies in this older video are black when viewed against the sun, and compare to the behavior of the same type of object in the first part of the new video above.

I also wanted to be able to simulate things like steam or water clouds, which, because they are made of smaller (and transparent) particles, scatter light forward instead of just reflecting it back. And I also wanted to support a mix of different types of cloud or transparency in the same scene. I've attacked this problem by rendering two illumination maps, the original, pure reflection map, and another which represents (mostly) forward scattering. (Right now, both maps are applied as-is, but I plan to make the response weighted by the transparent material in a later update.) This is what makes the transparencies shine when illuminated from behind in the top video, and gives the nice (if pixellated) murky sunset effect at the end of the video.

I was thinking of moving on to clouds next, but I could also implement an entire framework for visualizing and debugging the illumination maps, which would only take another week or two...

Thursday, August 23, 2018

Mr. Blinky

Well, that certainly is a creepy purple vaguely head-shaped lump. This is a slightly more complex model than the non-descript pillar of purple from the last post, and it blinks. It has separate shape keys to close each eye, and an animation linked to both of them. It also has shape keys for opening and closing the mouth, but I haven't created the tools to pick and choose which animation or key I am manipulating from the game engine's UI yet, so I'm stuck just showing one at a time.

Anyway, things move along. Maybe some additional UI tools before I go on to the clouds...

Sunday, August 19, 2018

Shape Keys

Shape keys, or morphs, or morph targets, are a way to control the shape of a mesh by having a number of different meshes (or targets or keys) with the same number and arrangement of vertexes, each of which represents a kind of target shape. Then, by adjusting a weight value you can use one or more of these shapes to influence the final shape. The video above demonstrates a very, very simple case where I have a big purple block, and one shape key attached to it, which is the same block with one side pulled out into an ugly protruding lump. By sliding the control on the lower left, I can run through an animation which makes the lump bulge out and then fade away (changing the shape key weight from zero to one and back again).

I got support for the shape keys themselves into the code last week, but I had to spend a bunch more time adding in support for UI controls and support for linking those controls up to the animation so that I could fool around with the weights in real time. (This is called testing in some circles.) Now that the basic support is in there, it should be a lot easier to set up other controls and debug tools from now on.

I know I said something about clouds last time, but I think the next thing I'm going to do is some more complete shape keys, e.g. a rig for animating a face or some such. We'll see how long that takes, and then I'll probably go back to work on atmospheric effects, unless I get distracted by something else.

Sunday, July 22, 2018

Right, Then

So anyway, blogging is now completely forgotten, so I'm just going to use this as my random hobby diary.

I'm building a game, or game engine, or some kind of thing, using obsolete technology on old hardware, for the hell of it. It's fun, for me, and gets me weird looks from my wife and kids.

I have a vision for a kind of space game, a bit of KSP, a bit of Minecraft, but not really either of those things. And since it has space, and planets, I've been trying to make planets that look reasonably good for a while now. One feature that's been in a long time has been atmospheric scattering, based on an old GPU Gems article (here). Works well enough. Indeed, it was a real eye-opener about how much math I could do in the GPU, even on an older system, and get away with it.

A separate trick I picked up in some game development article I've forgotten about, is using the color of the sky overhead as the ambient light value. This makes the insides of shadows blue lit in the daytime and reddish at sunset, for example.

Now, when out in space the ambient light value doesn't take this sky overhead thing into account, which is correct if you really are out in space, since the sky should be black. There's still ambient light, but that's a problem for another day. Anyway, I thought it might be a good idea to simulate the ambient light on the surface of planets as seen from space. They should be illuminated by the sky as well as direct light from the sun.

Turns out, the effect is very subtle. You might even say invisible.



Never mind the light positioning and lack of clouds. Unless you know exactly what to look for (the area along the north edge of the Arabian peninsula is a little brighter, but that might be affected by other factors too), you would never notice.

On the other hand, even the additional math to do this doesn't seem to have too much effect, so I'll probably leave it in. See it in motion on my YouTube channel.

Now, clouds, that would be cool.

Sunday, September 07, 2014

Eyebrows One Year Later

I was fiddling around and upgraded Blender to 2.71, and then, of course, I had to open up my old head-sculpture file to see if it worked. How about that... visible eyebrows. Perhaps some performance improvements have squeezed a few more polygons out of my hardware, or maybe I'm just forgetting how, exactly, it was broken. But anyway, looking back on it a year later it looks... kinda hideous.


Yeesh. I mean, it's OK, I guess, for an initial stab at something, by someone with almost no experience with these tools. But it's nowhere near what I wanted. One of these days I'll take another stab though, maybe at something similar, maybe at something else.

Wednesday, August 20, 2014

Ill Advised Posting

(I thought I wasn't going to talk about this. I guess I was wrong.)

So, the police officer who shot Michael Brown six times, was just doing his job, and almost half of white Americans think race is getting too much attention in the case. People are "playing the race card"? "Lawlessness knows no color"? What?

Even if Brown was shoplifting (which is not all that clear) or jaywalking, the penalty for these crimes is not death in the US, last I checked. The penalty for acting suspicious is also not death, but apparently a woman in the first article believes it is:
“An officer doesn’t have xray vision,” wrote Jennifer Hall, of Robertsville, Missouri. “He can’t tell if you have weapon or not until searched. So you act in a suspicious manner, we know what the consequences are.”
Seriously? If your white son was caught jaywalking and mouthing off, and was shot dead for it, that would be OK? Because we know what the consequences are for acting suspicious, right? Or is it that those people are lawless. Those people are criminals. Those people deserve to be treated with suspicion and executed if they step out of line? And those people just happen to be black?

We all set this fire. We need to own up to that.

Sunday, August 17, 2014

Minimum Wage

The title is a reference to the They Might Be Giants song. Really. That's what I was thinking about when I wrote it.

The other day I reblogged this thing on Tumblr about Walmart earnings and the salaries they pay their workers. For the most part my pinko bleeding-heart liberal friends seemed to agree: Walmart makes $27 billion in profit in one year, they could pay their bottom million employees $10,000 a year more and still make a $17 billion profit. This situation and others like it illustrates the crazy imbalance of our economic system, in which a few specialists in e.g. financial markets are paid hundreds or even a thousand times as much as regular workers who do essential jobs.

There was at least one person, however, who took issue with the statistics involved, saying that it didn't seem likely that a million workers, almost half of Walmart's total employees (and they are the biggest single employer in the world, apparently), were scraping by on minimum wage.

Now, the original post isn't actually criticism of Walmart specifically, so much. The second half of the post makes clear that this is about larger issues with the system itself, and Walmart is just a symptom. Whether Walmart only has to pay $10,000 more to a hundred thousand employees or a million doesn't really change the point, at least in my mind. (Wikipedia figures for Walmart also suggest that it might make more sense to use the profits after tax, which is only $16 or $17 billion, depending on what year you're talking about.)

On the other hand, checking Walmart salary information that's publicly available does paint a picture that seems consistent with the original post. I'm just looking at the first page full of results, and there are some reasonable and even well-paid positions. (Want to do well at Walmart? Become a pharmacist!) But the bottom-tier jobs pay $8 or $9 an hour on average. Being generous, that's $18 to $20 thousand a year. The "Careers to explore" links on that page include "Overnight Stocker" at $19k a year, and "Sales Associate" at $18k yearly. That's well below the poverty line for a family of four.

From the results from that page, a little less than half of the jobs on offer from Walmart (2073 of the 4205 positions summarized) are hourly jobs that pay on average about $19 thousand a year. If this is in any way representative of the mix of positions in Walmart's 2 million employee workforce, then yes, roughly a million workers are making poverty-level wages working for a company that made at least $16 billion in profit in the last year, after tax. Even if the results are strongly skewed, we're still talking about hundreds of thousands of workers.

Then there's this article, in which statements from Walmart spokespeople themselves lead one to the conclusion that a bit more than half of Walmart associates make less than $25,000 a year. Statistics are easy to misuse, but whatever way I look at this, it still seems like a lot of people are struggling to get by while a very few reap rewards out of proportion with their contribution to the company, society, or, well, anything. So, to repeat:

You know, this ridiculous idea that a worker on Wall Street who earns tens of millions of dollars a year securitizing imaginary assets or doing high-frequency trading is worth 1,000 times as much as workers who earn tens of thousands of dollars a year educating our children, growing or serving us our food, throwing themselves into harm’s away to protect our life or property, that this difference reflects the true value or intrinsic worth of these jobs is nonsense.

Sunday, May 01, 2011

I Said I Wouldn't Explain



That's the best image I could find. Well, no, actually, it's the first image I could find, which makes it the best. Click on the picture to go to the actual page.

That is a Japanese boxed lunch, a bento box. It has a picture (made out of something edible, I suspect) of a cartoon character on it.

Look closely. It is a rabbit, in a ballerina dress and tiara.

This is ありがとウサギ, the "thank you rabbit."

You could be forgiven for thinking it is, well, not exactly the most appealing character ever. You wouldn't be alone. The character was the subject of discussion on 2chan as to just how unappealing she, or it, was. This included the obligatory improved versions.



Much better.

But anyway, why? If you were in Japan, watching TV, any time after the March 11th quake, you know. This is why:

Click here

Immediately after the quake, there were no commercials to speak of. Slowly, the commercials returned, or rather, some commercials returned. The one linked above and a small selection of others from AC, all safe, inoffensive messages about being nice, were the only commercials, repeated sometimes three or four times in a row to fill air time. People actually complained that the "A~ C~" tune at the end was getting on their nerves, and the commercials were changed to remove it. You can find some pretty funny remixes on the tubes (and a lot of really stupid ones) if you look. None of them would make any sense either.

Everybody has seen this commercial, hundreds of times at least, in the last month and a half. It's to the point where seeing something like that almost makes me feel nostalgic, or maybe a bit sick. The idea of eating lunch with that damn rabbit on it is just...

Anyway, now I've explained. And it still doesn't make any sense.

Wednesday, March 23, 2011

Serenity

Warning, there may be spoilers.

So, Serenity. I haven't had a lot of time to watch TV in the past decade or so, outside a steady diet of Japanese comedy specials, so I never saw Battlestar Galactica until I bought the DVDs, and I never saw Firefly at all.

One of the few good things to come out of my recent two month "business trip" to Kanto, is that I sometimes have the time (and technology) to sit down and watch a film. First was Monsters (evaluation: Good. Pretty. Worth watching.), and Moon (evaluation: Fantastic. What thinking Sci-Fi films should aspire to.) This weekend, it was Serenity.

In short, this is a good film. It's a good film for fans. It's very different from Moon or Monsters, more like a bigger version of a TV show than a film. It was definitely entertaining, packed with action, very fun to watch. No regrets there. Still, this is not a movie that wil really stay with me. It didn't think any deep thoughts. Unlike Moon, I won't be lying awake at night thinking about it (unless it's to puzzle over some of the things I mention later). But, then again, you could say a lot of things about other, lesser movies, using sentences that begin, "Unlike Moon."

There were a few problems. The setting is an almost barely believable backdrop for a space-kung-fu-pirate-western that visits a different earth-like planet or two every week. It's perfect for episodic fiction. Too perfect. There was also the way the hero too conveniently acquires superpowers at climactic moments. The guy was run through with a sword, but he coughs a bit and gets on with business. And hey, it just happens that the favorite Vulcan nerve pinch of the villain doesn't work, because our hero had those nerves moved.

There was the dialogue. I understand that Joss Whedon is loved for his dialogue. I can see why. He does have a talent for it. On the other hand, maybe he should rein in that talent from time to time, or turn it in a different direction, because most of his characters sound like, well, how I imagine he sounds. They're all waiting, all the time, for the chance to launch a snark-missile into the conversation. Yes, it's funny, but it also sounds wrong when it comes out of the mouth of almost every character, in almost every scene. It's not terrible. Like I said, he's good at this. But it did, on balance, work against the film, I think.

One of the few things that I do wonder about the film even now, is how it was supposed to fit in with a TV series. Was it the climactic ending? Overall, it seemed good for that, but I wonder how River Tam fits in there. Was she a super killing machine in the TV series and the rest of the crew just never noticed until the movie? Or was this a prequel, in which case the funny pilot guy who gets impaled in a (largely successful) bid to make us think that maybe the major characters are actually in danger, was actually a minor character instead of an equal to the other, unkillable, crew members.

In spite of these, and another few nits I won't pick here, I still recommend it, at least for SF fans. It's fun, and maybe that's all it intended to be, which isn't so bad after all.

Tuesday, December 21, 2010

The Story of How Brownie Learned to Play Piano

One day, when Brownie, the elk who looks like a chipmunk with horns, was doing her job in Yellowstone National Park, conducting a nature talk, a little boy said to her, "Did you know you are an elk?" And Brownie had an enormous freak out and made the boy cry, and then she apologized and gave the boy a candy, but she still decided she needed to have a vacation.

So she talked to her supervisor, who was not an elk, and he suggested a trip to New Mexico. "I hear the desert is lovely this time of year," he said.

So Brownie the elk, who looks like a chipmunk with horns, got a Greyhound bus to Albuquerque. The bus driver looked at her when she got on the bus and said, "Did you know you're an elk?" But she just took a deep breath and said, "Yes."

She wandered around the desert, which was lovely that time of year, and took pictures. She met a man in the desert, and his name was Tom. The man's name was Tom, not the desert. Tom said, "I've never seen an elk in the desert in New Mexico before." He offered to show Brownie the special places in the desert where flowers grow, and which are especially lovely this time of year.

Tom took Brownie to special places in the desert, and she took lots of pictures of flowers, and felt very glad she had taken a vacation. She was so happy she thought she wouldn't even have a big freak out if someone asked her if she knew she was an elk.

Now Tom was a pianist in a blues band in Albuquerque, and he was a very good pianist. Brownie went to see Tom playing piano many times, and sometimes she took pictures of that, too. Tom showed her how to play "Chopsticks."

Plink plink plink plink plink plink.
Plink plink plink plink plink plink.
Plink plink plink plink plink plink.
Plink plink plink plink plink plink.

Then her vacation was over. She said goodbye to Tom and the desert and the flowers and took another picture of all of them, and got on the bus to Yellowstone. When she got back she went happily back to her job giving nature talks, and when children and bus drivers asked if she knew she was an elk she would say, in a very friendly way, "Yes, and I can also play piano!"

The End.

Friday, February 05, 2010

Additional Thoughts

I think that last post needed more time in the cooker. I'm too lazy to go back to it now, though.

And I think I need to draw and post more pictures.

Thursday, February 04, 2010

Worse than Television

"What have you created and released?" Charlie Stross asks.

Well, as anyone who looks at this probably knows:
  • two short novels, with a third on the way
  • A few short stories (temporarily unavailable because the Dead Channel is down)
  • More than a decade ago, Mingw32 (which has been much improved by the efforts of others since I moved on)


I've sent out a few pictures here and there as well.

On the other hand, I don't believe (at all) that creative people are obligated to give away their work for free. Some of my best friends are authors, or aspiring authors. I've given my work away for free because, while I love to write, I don't have the need or the time and energy to get paid for it, at least for the time being. It would take a lot of work to go pro. There's probably another blog post in that whole topic.

What prompted this, though, aside from a desire to brag (sorry), is piracy.

Specifically, I have this gut feeling that piracy is not the root cause of the crisis in publishing (or the crisis in music). Which is not to say there isn't a crisis, or that copying somebody's work against their will isn't wrong. However, I have the feeling that the industry's problems are coming from elsewhere. One of these places is a general economic downturn. We're all less willing to spend money on stuff.

The other part is a proliferation of distractions, many of them legitimately free. I could easily spend all my time on the internet, on twitter and in web forums, and without infringing on anyone's copyright. I hardly watch TV any more at all. I have DVDs for a series that I bought last year still sitting unwatched. I have deliberately started scheduling reading time for myself so I don't spend all of my time on the net and forget the pleasure of books.

Some of these distractions are even "creative." I might not be writing and drawing at all without the internet. I can spend time editing Wikipedia articles or participating in online discussions. I can spend time looking for references and information related to my next project. This blog itself is a distraction from reading I could be doing to help some professional author make ends meet. It's part of the attraction of the internet, that you can be doing creative, or at least interactive, things with it. It feels so much more fulfilling than vegetating in front of a TV set. And yet, this is, I think, helping to destroy the publishing industry.

What should we do about it? Hell, I don't know. I'm certainly not going to suggest people should step back from the keyboards and leave it to the professionals. There has to be some recognition that doing great work requires dedication and a lot of hard work that should translate into a tangible reward. I worry quite a bit about works of art and literature might not be created because talented people can't make a living producing them. I think eventually a balance will emerge, but I also think it's going to be messy for a while.