Project Frontier #6: Growing Grass

By Shamus
on Jun 16, 2011
Filed under:
Programming

frontier6_8.jpg

I think we’re done mucking with the terrain for now. There will be optimization to be done later, but for now it’s stable, fast and it accomplishes most of what I need it to do. We’ll revisit it later when I add more geographical features, but for now it’s time to move on to putting stuff ON the terrain.

Actually, no. Let’s do something quick. The sky is really bugging me. Right now I’m just using a solid color to match the fog, so that things in the distance will fade into the sky. That’s nice, but we can do a lot better with very little effort.

Surprisingly enough, step one is to create a… cone?

frontier6_9.jpg

We color bottom rim the same as the fog color. The tip is colored to be the same color at half brightness. This isn’t a texture map or anything. Just a plain colored polygon. Your graphics card is actually personally insulted when you render these. It’s like asking Superman to bend a bar of Play-doh.

frontier6_10.jpg

We render this so that the player’s head is always inside of the cone, with their eye even with the bottom rim. The advantage is that this is fast and cheap. The other advantage is that we have tricked the unwitting player into wearing a dunce cap. If we render it so that everything else ends up being drawn in front of the cone, we end up with:

frontier6_11.jpg

NOW we can put stuff on the terrain. Let’s start with grass.

The most common technique for making grass is to take two rectangles and intersect them at a right angle.

frontier6_12.jpg

Then you just slap a picture of grass on them and call it a day. Actually, I guess this was the most common way of doing this ten years ago. Today, people use more polygons, and alpha-blending prevents them from intersecting to panels like this. But this project is all about building a rocket ship out of stone knives and bearskins, so that’s how we’re doing this.

True story: The tufts of grass in Oblivion have twenty eight polygons. For comparison, my little-two panel model is just four. (Each rectangle is two triangles for the purposes of rendering.) Back when Oblivion was new, I couldn’t turn on grass at ALL, because it would bring my poor little machine down into single-digit framerates. LOW single digits.

Someone came out with a mod that was nothing more than an alternate grass model. It replaced the twenty-eight polygon monster with a simple pair of panels like I have above. The result? The game ran about ten times faster. Visually, you could barely tell the difference. When you stood at a certain angle and saw a lump of grass in isolation (perhaps on the edge of a grassy area) you could tell the difference. A bit. And even that visual gap could have been fixed by simply moving from four polygons to eight. (So that from above, the panels form an asterisk shape.) Twenty-eight polygons is insane, and even on today’s hardware using the Crysis 2 engine, I would still slap the artist that made a twenty-eight polygon tuft of grass. There are just so many ways we can better use that power.

So, I take a grass texture and slap it on my panels. The result?

frontier6_13.jpg

Looks okay. Now, I came to this spot for screenshots for a good reason. I like the really stark difference between the bits of ground here. My plan is to just render these tufts of grass to match the texture underneath them. Let’s add this coloring, and add a few more bits of grass.

frontier6_14.jpg

Hey! Why is the grass still greyscale? See, the grass texture is white, and my plan was to color the polygons to make it match the terrain. I could use a texture with green grass on it, but then I’d be stuck with a single shade of green. I have thousands of subtle shading changes all over the terrain to make it look diverse and vibrant, but that’s all for nothing if I’m going to carpet over it with a fixed shade of green! It defeats the entire purpose of what I’m trying to accomplish here. So why is the grass white, even I’m coloring the polygons different shades of green?

Oh wait. Now I remember.

Head. Hit. Keyboard.

I’m using what’s called the “fixed function” rendering pipeline. This is pretty much the default behavior for OpenGL. See, how it works is there are two ways of coloring polygons. One is using the color command. This is like what I used on the sky. You tell OpenGL what color you want the vertex, and it will do a nice neat fade from one vertex to the next. The other technique is to use the lighting system. If you use that, then if you want a polygon to be green you need to aim a green light at it. These two systems are mutually exclusive. The sky works because I turn lighting off when I draw it. (It wouldn’t make sense to have the sunlight shine ON the sky. It would not look like sunshine. It would just put a big vertical stripe up the sky.)

If I want a lighting system that incorporates polygon coloring, I’ll have to make my own. I can either do that with vertex shaders or by turning off all OpenGL lighting and doing all of the lighting calculations myself. Both of these steps are complex and time-consuming, and might require changes to the low-level bits of my engine. (Including the terrain system, which I just resolved to leave alone for a bit.) Can I use vertex shaders when I’m using OpenGL through SDL? Wait, now I have to read up on what functionality is available with SDL. Oh, there’s a beta version of SDL that might offer…

No. No no no no. I will take this step eventually, but this is NOT the right time for it. I started this project because I want to experiment with my ideas for procedural content, not so I can muck out implementing my own lighting model. That will be a time-consuming distraction, and will lock me in to certain decisions that I’m just not ready to make yet.

So we need a way to fake it. Let me think…

(The next day….)

Okay, I think I’ve got it. First, I render the grass, as before. I have lighting enabled, so the grass is white.

frontier6_14.jpg

Now, I turn off lighting and render all of the grass polygons again, but this time using the colors I want.

frontier6_15.jpg

Now, I can change a setting so that when it renders these polygons, it will ONLY render them where there is already a pixel at the exact same depth, and nowhere else.

frontier6_16.jpg

I can also set it to blend the results of the second polygon, instead of just overwriting them. If you’ve ever used Photoshop, this is almost identical to using the “multiply” feature on a layer. It changes the color of the stuff underneath.

frontier6_17.jpg

Almost there. But it’s too bright. I fiddle with the filter a bit until I get the results I want.

frontier6_18.jpg

It’s good. Up until now I’ve had the grass only once every five meters, for testing. Let’s increase it to full density and see how it looks:

frontier6_19.jpg

Good enough. There are drawbacks to my approach, though. It won’t look right with fog. It can’t. If I have fog touching the grass, the affected grass will seem to glow. If I use dark fog, the grass will turn very dark. Basically, if the fog gets close enough to interact with the grass, the grass will no longer match the terrain and the two will look wrong together. This is a small problem, and I’m willing to tolerate it until I decide on a lighting model.

You know… this has me thinking. The grass tufts are two intersecting panels. What if I took those four points on top, and connected them?

frontier6_20.jpg

Yeah, like that. And now if I add another region to the texture and change the coloring of the top…

frontier6_21.jpg

Yeah.

Well, we’re now at the end of the features I’d already mapped out before I began. But from here on I’ll be making it up as I go. Which should be interesting.

Wait. One more:

Click for larger view.
Click for larger view.
Enjoyed this post? Please share!


A Hundred!2020202Many comments. 162, if you're a stickler

From the Archives:

  1. poiumty says:

    So have you stopped writing entirely to focus on programming now?

    • Shamus says:

      Shhh!

      If you bring that up I’ll be overcome by guilt and common sense and go back to writing!

      • MadTinkerer says:

        Personally I’d prefer if you took a couple weeks off to just write about Project Frontier and other progamming subjects. But then I’m trying to learn this stuff myself.

        • Eldiran says:

          I agree, Project Frontier is way more interesting than Project Book. Maybe that’s just because I’m a programmer. Or because Project Book is top classified secret until it’s out.

          • Glenn says:

            Seriously, I’m all over this. I’d be interested even in a more in-depth discussion of specific rendering pipeline/methods and programming stuff, even if I didn’t understand it all. I’ve got an abstract understanding of how graphics work, but no actual idea what to do with the programming part of it.

          • Henebry says:

            Project Book would be more interesting if you were willing to share with us about the writing process. For some reason, your model for novel-writing is drastically different from your model for app writing. You don’t need to do novel writing locked up in a room—at least not in my opinion,.

      • X2-Eliah says:

        I wouldn’t mind seeing a few blog posts about your techniques of writing as well, or your approach to location/character design and descriptions.

        • Retsam says:

          Though these sort of posts would probably be more meaningful after the book is published. (Though I suppose it would be worth writing them now, while it’s fresh in mind)

      • poiumty says:

        ‘kay. I’ll never bring up your laziness, lack of common sense and your refusal to stick to the project you depend on ever again. Never shall those 3 things be ever talked about again. Your shameful secret is safe with me. You can go back to programming now. Everything is fine. Just fine.

      • some random dood says:

        Decisions, decisions…
        While I enjoy your articles on programming, will admit I am really looking forward to the book! Also sounds like the book is only a few months away from completion and a possible publish date, but while the rate of progress on the program is astonishing, it ultimately seems a longer-term project.
        Guess that I am trying to say – pleeeeeeeeeeeease finish the book!

        • MichaelG says:

          Unless he’s self-publishing it as e-book, it won’t be available until a year after he finishes it. At least, according to what I’ve read about the publishing industry.

          • Knight of Fools says:

            A year if he’s lucky. Some new authors take years to get published. Shamus is a pretty capable writer, but he still has to convince the publisher that the book would make them money, which is a long, arduous process full of errors, lack of understanding, and general human failings.

            Unless, of course, he’s already found a publisher, or someone that reads his blog is publishing it… But even then it’d still take forever.

            And taking a break is good for writing, especially if you fill the break with writing about other things. It clears your mind a bit and gives you a clearer perspective about your main project.

            [/not professional opinion]

      • random_physicist says:

        I love reading about your programming projects. It’s a very interesting look under the hood of a game and I think procedurally generated content is pretty neat (it has a significant elegance to it that I like).

      • RPharazon says:

        Hey now, take a break.
        As anyone who has done a Let’s Play (or any creative project ever), the risk of burning out due to schedule obligation is very, very real.
        Take time off, do this, do anything you want, just take a break, and when you’re set, come back to the things you want to do.
        You work for yourself, not others.

      • Sem says:

        As a programmer myself, I really like the programming posts. More in-depth would be even better but that’s not the focus of this blog and then most non-programmers will have a hard time following.

        I also bounce around a lot between projects on account of having the attention span of an distracted high-strung squirrel. Usually, the moment I figure out how to do it I lose all interest. Figuring out the process is interesting, actually doing it is secondary for me.

        The only time I actually finish a program is when it has a practical value for me. Even then, I usually only make the processing code and then just slap a quick command-line on front of it.

      • SirVivor says:

        Might I advocate the writing of a paragraph of short- and long-term goals for the book if you intend to put it down for a while? If you haven’t already. What do I know? I’m just the Internet. Don’t listen to the Internet. That guy’s a jerk.

  2. Zaxares says:

    Wow… Talk about a brainstorm moment! Nice job on finding a clever way of creating flowers. :D

  3. Raynooo says:

    Those flowers look pretty good nice job !

  4. Epsilon Naught says:

    Holy shit. For a system hacked together in a week, using 16 (32? I dunno. Small enough) bit textures, that last screenshot is as good looking as anything I’ve actually seen in a game.

    • Yes, it looks AWESOME. I mean, there are still things that could be made even more awesome, but this is still pretty durn cool.

      You know, you could use this same process to fix your problem with the “snow” in colder areas, yes? Cover the “snow” with a “grass” texture that was white and just sort of softly curved? Something like that?

    • Glenn says:

      Agreed. I’m really impressed, especially with the attention you’ve payed to low-spec machines. I love the look of it – it reminds me of Daggerfall/Morrowind, but more stylized. It’s pretty.

  5. Simon Buchan says:

    OK, that grass looks amazing! I do think you want to use shaders in this engine eventually though – they will save you a lot of effort thinking about ways to fool the fixed functions into doing what you want, and it’s easier to read, to boot.

    I’d given up on SDL ever properly supporting OpenGL – the last release was 3 years old last time I looked, but it seems they are just taking forever rewriting it – which is cool with me if it ends up not sucking because of it. I’m not really doing anything I care to release publicly ATM though, so I’m not worried about portability. That and the whole OpenGL on Windows sucking thing…

    • WJS says:

      This does seem like a hacky way of doing it. I don’t do graphics stuff myself, but it does seem to me that using shaders falls into the “doing it right” camp.

  6. JPH says:

    That last screenshot actually looks beautiful. I’m really digging the art style.

    This makes me want to learn to program. Someday I’ll check out that C++ guide you linked to forever ago. I still have it bookmarked.

    • RejjeN says:

      Any chance you could post the link? I’ve been considering getting back into c++ for a while now and I think reading Shamus (dev blog?) has gotten me interested again xD

      • Glenn says:

        Yeah, I’d be interested too. I’m not learning nearly enough about C++ in my computer science classes. It’s mostly Java or assembly language. Those are fine, but I’d much rather be working with C++ and end-user software than server-side stuff.

        • CrushU says:

          C++ vs Java: Everything Java does for you, C++ doesn’t. C++ allows direct access into memory, and doesn’t do ANY garbage collection whatsoever. Java allows only single class extension, C++ allows multiple classes to be the parent class.

          Essentially, Java is a safer version of C++. You can’t hurt anything too badly, since it runs in its own virtual machine anyway. That said, you don’t have near the power or versatility that comes with C++.

          Java is training wheels, C++ is a 400cc Suzuki motorcycle.

          • Nick says:

            That’s a point of view. Java actually has a lot of libraries to achieve things that can’t be done nearly as quickly as in C++ – it all depends on what you’re trying to do.

            Also, java does have multiple inheritance through interfaces, though that does restrict what can be inherited that way. Which is probably a good thing tbh – I can’t think of a situation where multiple class inheritance couldn’t be sorted out by either a) designing it better in the first place or b) just keeping a reference to the secondary object and operating on them.

            Anyway, broadly speaking – C and C++ are best for graphics and performance-critical applications; java is better for server side applications and coding more quickly

      • JPH says:

        Link!

        Hopefully you have a better attention span than me…

    • Mephane says:

      For starters into programming at all, I would suggest something less difficult, like Java or C#. They both share a lot of concepts with C++, and what they don’t have is usually exactly the more difficult stuff – manual memory management, pointer arithmetics *shudder*, implementation/header file organization, arcane link-time and runtime dependency management (my bigges gripe with C and C++; in order to use another DLL, you need a header file, and a lib file, unless you use LoadLibrary, if you export classes both need ends to be built by the same compiler+linker; and it all works only until you stumble upon a heap corruption coming out of nowhere). Professionally I am a C++ developer, but for my home projects I prefer (no kidding) F#. It’s just amazing how much you can accomplish with so little clutter in your code. However, F# is more difficult to read than C#, so I don’t recommend it for beginners.

      So if anything, trust me in this: To start learning programming, pick any managed language. It doesn’t even matter so much which one. The very feature of automatic memory management saves you so many headaches that you will have to go a long way until you might say “hey, I could do that better with raw access to memory”.

  7. froogger says:

    I don’t know what’s wrong with me, but I just love pixel-tricks that fool the eye! I bet if you lived in the 17th century you’d be painting fake columns on walls for a living.

  8. Pete says:

    So here I was thinking “sort of neat, but theres just too many visible edges for my taste”… and then, flowers.

    *tips off imaginary hat*

    • Fists says:

      Similarly, I was coming up with a witticism about Shamu’s games are always just endless shades of green, then, flowers.

      One of my favourite things about oblivion was the vibrant colours and contrast in the world so I’m digging this.
      (The settings I played oblivion on at first made it look like daggerfall and framerate was still ~15, then I added OOO and had about 2fps in combat, looking back I’m amazed at my patience)

  9. Narida says:

    Yay! Now your landscape looks better than the ones in Mass Effect, and that was a triple-A game! Skybox still needs some work though. :-P

    In oblivion the grass waved in the wind, might that have something to do with the high polygon count?

    • I don’t think the grass moving in the wind has anything to do with the polygon count unless they settled on that enormous number of polygons because the animator had this sweet idea for making the grass move that involved 28 polygons for some reason. In which case both the animator and the artist need to be slapped.

      Titan Quest has some awesome-looking 2-polygon grass (I think, it’s just a straight line, that’d be 2 triangles, right?) that moves when your character and mobs run through it. It has some minor issues–if your view is precisely end-on to the grass it looks a bit two-dimensional and thus fake, and in some places it’ll bounce back and forth like it’s on springs if you stop which looks really goofy (it should just shake once, not over and over and over and over). But it still looks pretty good.

      DDO uses the intersecting-polygons-with-textures thing for tree foliage and in places it looks really awful. Other places it looks fine. In general the awfulness occurs where you can get right up to the foliage and see that it looks just like a stack of leaf-colored cardboard boxes. Dragon Age had the same thing with a haystack which made it look like this really bizarre miniature Epcot. When you can SEE the geometric shapes these things tend to look horrible.

    • Swedmarine says:

      What do you mean “Skybox”? By reading the text you should boviously know it is a Skycone! /badjoke

  10. ronarscorruption says:

    I absolutely love the flowers. It turns the grass from meh to both realistic and beautiful. Good work on that. I look forward to seeing more of this.

  11. Aelyn says:

    Very nice. The flowers really bring it to life. Nice solution, too.

  12. X2-Eliah says:

    Shamus, why don’t you change the grass-polygon width & height based on the colour/location too? So you get low, fat grass on green areas, thin tall stalks in yellow and such.

    Edit – also, is it me or is the scale waaaaaaay off? I thought those brown mountains were like 5-10 meter high, not half a meter mounds of dirt. Alternatively, now it looks like the grass is gigantic.

    • Dnaloiram says:

      Well, it looks like there are some mountains in the distance in that last screenshot, so hopefully there’s some dramatic terrain.

    • Paul Spooner says:

      The flowers aren’t giant, they’re just in the foreground!

      Seriously though, I agree with you. I’d prefer the grass to be… about four times shorter. Get out the lawnmower again Shamus!

    • Kacky Snorgle says:

      I had the same feeling about the scale of the vegetation vs. the terrain clear back in Project Hex. Now that it’s happening again in this version, I’m thinking it’s probably just part of the stylized look that Shamus is going for. Still isn’t the choice I would’ve made, but then, I know zero about training a computer to make pretty pictures. ;)

  13. MadTinkerer says:

    “Actually, I guess this was the most common way of doing this ten years ago.”

    And in Minecraft. ;) It’s used for grass, wheat, mushrooms, flowers, and basically any plant that isn’t made of solid blocks.

    Also: Project Frontier is looking preeeetty sweet. :)

  14. paronomasiac says:

    It’s not cutting edge graphics. It’s barely average for a decade ago. But it is gorgeous. One man, with a pet project in his spare time, creating something that’s more visually appealing than every single first-person shooter created in the last five years?

    Brilliant. I salute you, sir.

    • Turgid Bolk says:

      Aesthetics contribute more to a game than graphics. :)

      Especially when dealing with low-end machines, strong visual design is much more important than raw graphical power. Extra Credits just did a show on this, too.

  15. Zak McKracken says:

    One thing I did not understand:
    If you managed without problem to color the grass texture on the ground in many many shades, then why does the same method you used there (btw: which method are you using there?) not work on the grass objects?

    Also: Looks even prettier now. Like it. Would probably not look so good if your head was level with the grass, but from a reasonable perspective it’s got this impressionist feeling … very cool.

    • Shamus says:

      The ground texture is actually a procedural texture made specifically for that section of terrain. I describe the process here:

      http://www.shamusyoung.com/twentysidedtale/?p=9844

      I turn off lighting, generate the texture, slap the texture on the terrain, and then render the terrain with lighting on.

      Using the same trick for grass would mean mucking about generating hundreds of textures for each different color. Or group. I don’t know. It would be messy.

      • Speaking of grass colouring:

        To get the grass to interact with fog nicely, can’t you tell it not to blend with fog at all, then simply blend the hues themselves with the fog colour before applying them and increase their opacity based on how far away from you they are?
        That should roughly sync up with the actual fog and still look nice if the two overlap.

        Making them transparent at a distance might also work, I think that’s how a lot of games tend to handle detail objects at a distance.

      • Paul Spooner says:

        Okay, maybe this is oversimple, but couldn’t you have the terrain and the grass render together? Have the terrain generate a grass texture while it’s doing its procedural texture (the grass geometry texture appears to be procedural already) and render them at the same time.
        You’ve probably thought of this and a hundred other ways to do it already. Just wondering.

  16. DrMcCoy says:

    If you don’t want to be bound to OpenGL 1.2 that’s in standard SDL, but still want to be portable and reasonable fiddle-free, you should maybe look into existing libraries for this sort of thing.
    For example, I for one found GLEW to be very neat. It’s relatively easy to use, and if you care about this sort of thing, you can also just put its 4 source files into your code tree instead of dynamically linking to it.

  17. wasyl says:

    Are you sure there is no way to use fixed GL lighting?

    My OpenGL is plenty rusty, but wouldn’t something like glColorMaterial(GL_DIFFUSE) + glEnable(GL_COLOR_MATERIAL) help you get your grass correctly colored without doing all those hacks? I’m not sure how those settings interact with vertex buffers, but without them, this would transfer the glColor(..) colors to the material used by the fixed-pipeline lighting.

    Alternatively, you could just use glMaterial* for each region or however often you want to change the color.

    You could also use GL_AMBIENT if the grass is not supposed to be shaded with the lighting, I think.

    Oh, and great project. I’m waiting for the updates to hit the RSS each day at work, so do keep going. It definitely looks great for what it is.

    • Shamus says:

      That was my thought as well, but it just never looked close to right. If I was using any sort of colored light (like yellow sunlight) the colors never matched. There might have been some combination of DIFFUSE / AMBIENT that would have done the job, but I couldn’t find it.

      • Rowan says:

        Sunlight’s not yellow! It’s pure white, your average light bulb’s yellow.

        • Shamus says:

          …which would be relevant if this was a realistic simulation.

          Games and movies use yellow light all the time. It’s really handy for sunrise. If you’ve ever played WoW, think about how yellow Westfall is. Unrealistic, but darn pretty.

        • silver Harloe says:

          It’s not _pure_ white, otherwise that whole “determine the contents of a star by examining the spectra” trick wouldn’t exist. But, uh, close enough.

          Anyway, that’s what it is in space. After going through a few miles of atmosphere, the color is changed somewhat, I thought?

          • Bodyless says:

            Not enough to be noticed by human eyes. Oxygen reflects some of the blue light so the sky is colored blue. Dirt particles in the air reflect some red light, which causes the sunrise/dawn to be colored red, because at this times the light travels the longest way through the atmosphere till it reaches the eye.
            This is enough to color the sky. But the lightening through the sun is still white.

          • Kaeltik says:

            Our eyes and brains have evolved to accept the overhead solar spectrum, filtered by the atmosphere and received by our trichromatic retinas, as “white”. This yields maximum contrast in the best lighting conditions. Organisms that depend on vision to spot camouflaged predators or to determine which leaf/fruit is ripe/spoiled/poisonous are highly selected for maximizing contrast, given their available optical pigments and the prevailing lighting conditions.

            Our eyes are not perfect, so much of the effect is achieved by processing in the brain. Thus we usually perceive the lightest color in our visual field as white and the darkest as black. This processing is fairly flexible, which is why sunlight continues to look white until conditions become extreme (sun near horizon, high atmospheric aerosol content, etc.).

            We can expect visually oriented extraterrestrials to have evolved under similar pressures. Even if the star of their home system is much redder or bluer than the Sun or if their atmosphere has very different absorbance/scatter properties from ours, they should still perceive their starlight as white and perhaps ours as tinted.

        • Zak McKracken says:

          Actually, if you want to be precise:
          Sunlight outside of the athomsphere is pure white (that is: 5800 K white, because that is the temperature on the sun’s surface). Inside the athmosphere, the ambient lighting (what happens if you hold a white piece of paper in the sun) is about 6500K, so more blue-ish white than in space. This results from the fact that the sky is blue, and what the white piece of paper gets is direct sun light as well as ambient light from the sky.
          So on a sunny day, the sun is yellow-ish, compared to the ambient light. If you put the same piece of paper in the shadow (maybe just behind another piece of paper of the same size, all it “sees” is the blue sky, and that makes shadows appear slightly blue.
          What does this give us? Direct light is slightly yellow, ambient light is rather blue. Exactly what Shamus says is the way things are done in CG.
          On an overcast day, these things are averaged out by the clouds, and you have no such distinction anymore. On an evening, you get not only reddish light from the sun but also from the surrounding sky, and clouds in the west, while the sky in the east is deep blue. Gives a nice lighting situation, and yes, relative to the percieved white (i.e. the sum of all ambient and direct light in the observers vicinity, the sun is yellow or even orange.) BTW. The yellow and red you see at sunrise or sunset is exactly the yellow and orange the blue sky is missing during the day.

          => So using a slightly yellow sun is not only artistically but even physically OK. While of course some exaggeration does help to set the mood.

  18. Zukhramm says:

    Reading this one question comes to mind. Why use two squares for grass instead of two triangles for the grass? The shape shouldn’t matter since most of it is transparent, but wouldn’t halving the polygons used pretty much double to amount of grass that could be drawn?

    • Shamus says:

      Well, the grass texture itself is a rectangle, so if I only used a triangle I’d be cutting it off somewhere. Assuming I understand the question.

      • Zukhramm says:

        Yes, it would cut off, but since the shape is predictable, the texture can be made with the cut off in consideration, with the image of the grass only on the part that is not cut. The question is, is it worth it, to save those two polygons?

        • X2-Eliah says:

          No. No, it’s not.

          • Zukhramm says:

            With the argument?

            • X2-Eliah says:

              I would bother to do the calculative argumentation for it if two extra polygons with a single unstretched texture would matter in the least bit to any 4-year-old graphics card on a mediocre laptop.

              • Zukhramm says:

                Of course two polygons do not matter. But it’s only as low as two polygons if that goal is to draw one single tuft of grass, but if considering a field or more full of grass the amount of polygons will be significantly higher.

                • X2-Eliah says:

                  higher than constantly re-calculating the cutoff and so on on the cpu, when the game is destined to be heavily cpu-bound already?

                  • Zukhramm says:

                    I have no idea what calculations cut off calculations are involved when drawing a texture on a polygon when the texture is bigger than the polygon. That’s why I’m asking. Of course it could be done with a texture smaller than the polygon, if that is easier.

                    If the shape of both the polygon and texture is known before hand, why does the cut off need to be calculated more than once?

                    • zacaj says:

                      Theres no extra calculations. I dont think X2-Eliah gets what youre saying. The cons are that youre going to need more texture space (none really, you can use clamping), and youre going to use more of your fillrate, which could be helped, but not mitigated using the alpha test (auto cancel the pixel if its transparent)

        • Dev Null says:

          Well for one, it’d mean adding vertexes to slap the flower polygon on top. As it is, he adds a polygon but no new vertexes. (I’m not real clear on how much difference that makes, but its a difference, anyways…)

          • Zukhramm says:

            Sorry, I don’t understand what you’re saying at all. Maybe I don’t understand what a vertex is, is the term used differently when involving computer graphics? Or I’m missing something vital, as I said I don’t really know anything about this. But how does a rectangle require less vertices than a rectangle?

            • Rick C says:

              It doesn’t. He’s reusing the vertices that form the top of the grass, having them double up to form a second (well, third) rectangle, on which he draws the flower.

              By contrast, drawing the grass as a triangle (see the picture link a couple comments down is one triangle, as opposed to the two a rectangle is made of.

              • Zukhramm says:

                Oh, that’s what I get for not reading carefully enough. I didn’t realize it was about the flower and not the grass.

              • Piflik says:

                Actually, connecting these Vertices to create a new Polygon does create additional Vertices as well, at least in all engines I know, since they divide every mesh at every Vertex-Normals-/UV-/Material-Border…also a shape like that (without additional Vertices) would be Non-Manifold Geometry, which is all kinds of bad ;)

          • Atarlost says:

            No extra vertices. Just put the base of the isosceles triangle on top and half the height buried. Tufts of grass tend to puff out from a narrow base so it actually fits real grass shapes better.

            Okay. This is wrong. My browser spellcheck doesn’t think vertices is a word but it wants to correct it to vertices’s. I have a strange urge to take Daniel Webster’s name in vain.

    • zacaj says:

      You mean like this? Or something along these lines?
      PICTURE

      • Zukhramm says:

        Yes, it should probably be bit flatter maybe, but that’s the principle of it.

        • Sord says:

          Based on the ideas in the other branch, how about something like this http://dl.dropbox.com/u/8269747/grass_texture.png

          • decius says:

            Instead of eight rectangles in an asterisk, how about 3 in a triangle? That cuts the triangle count from 18 to 7 (since the flowers can now be put on one triangle.)

            If we reduce the number of triangles per quality area of grass by x%, we can include 1/(1-x)% of the quality area of grass visible at any given time for roughly the same cost. Saving one triangle out of 5 is just as good as saving 100 out of 500.

          • Topaz Wolf says:

            Why are you using four polygons for a texture…

            I am joking, but you must realize that computers can only make perfect square grids (they can make more than that but only by changing rules and using more memory, since its just a changed square grid). A texture would not be created in an equilateral triangle, but a right triangle which is half of a square. A texture would almost always be simpler to create in a square using two triangles since the only other way to do it is to make it on a single triangle with a sizable amount of left over space on one side, leaving gaps in the grass.

  19. Hal says:

    I just realized something. Your final screenshot reminded me of someplace: Azeroth.

  20. zob says:

    Some programmers tends to get arrogant after a while, now you know the reason. There aren’t many professions that lets you create worlds from scratch :)

  21. Jonathan says:

    Nice!
    I have seen bullets impact the skybox before and kick up puffs of dust, and leave marks on it. To avoid this, you could also make the skybox a sphere, and have the world sitting about 1/4 of the way up from the bottom of the sphere, so that the sky goes farther away from the island before starting to arc over it.

    • Making the fog and the horizon colors match up would be a huge pain in the ass then, nyet?

    • DaFinchy says:

      Far simpler to merely exclude it from any collision detection.

      (tl:dr – physics =/= graphics. Just don’t bother checking.)

      Better to not include it in the first place. Physics and graphics are normally separate systems, as they should be; checking collisions against all the polys from the graphics engine is simple and brute-force, dumb and inefficient. Bullet hit detection on a guy, for example, usually checks against a basic marionette made of primitive shapes, not the complex deformable mesh you can see. So long as there’s no “physics shape” for the sky, there’s no problem.

      • droid says:

        That reminds me of a game I built a while ago. There was this strange glitch where the ground would disappear after a while. Turns out the 2 polys we were using for the ground were derived from the same class that players and objects were derived from, and it was taking damage and being destroyed. Not as weird as the bug where you couldn’t fire if you didn’t move from the default spawn. Because that’s where the skybox was, your bullets were being absorbed by it.

  22. webrunner says:

    It’s funny how you had a goal to get something abstract and pixelly and ended up with something that looks more realistic then a lot of games that try to look realistic.

  23. Jeff says:

    Shamus, I love watching you world-build as much as the next guy, but I hope that someday one of these projects progresses far enough for you to work on other gameplay elements (balance, AI, plot) as well, since I know you have a lot to say on those topics as well, and you have yet to really explore them in any of your projects, as far as I can recall.

    • DirigibleHate says:

      Heck, I’d be fine if he just finishes it as an engine (Or, I guess, world generator would be more accurate), and releases the source code so other people can add things on top. Heck, I’ve seen worse things packaged up and sold as game engines before, and this one’s even documented!

  24. Kian says:

    I’m wondering, how do you get the normals for the terrain (for lighting)? Are you giving each vertex the same normal as the triangle surface (meaning each point has different normals, for each triangle it is a part of) or are you joining them to get smooth shading over the surfaces? And if so, how are you doing it?

    • Shamus says:

      Normals are computed after the elevation points are calculated. Yes, normals are done per-point, not per-triangle.

      When calulating the normal for one point:

      normal1 is the vector from the point to the west of our point to the one east of it.
      normal2 is the vector from the point to the north of us to the one south of us.

      The normal for our point is the cross product of these two.

      There are some tricky bits when you’re calculating the normals for the edge of a page of terrain data. On the west edge, it can’t look for the point due west, because I can’t count on that page being in memory. (If I did, it would lead to a cascading failure where pages would keep invoking their neighbors until the program tried to jam the whole world into memory at once, and would most likely perish in the process.)

      So on the edge I just fudge it and assume the next point will be level with this one. Before I added grass, you could see these seams every once in a long while. They were far apart, subtle, and were only visible on certain shapes of terrain, but they existed. Now with grass they’re basically hidden forever.

      • Kian says:

        Ohhh, yes. I see. I had been looking for ways of doing it, but I guess the solutions I found were more general and couldn’t take advantage of the fixed grid on the terrain.

        Thanks :D

  25. Kelhim says:

    Considering what you’ve been achieving in only a couple of weeks I’m almost embarrased how slowly my own project is going on, even though it is a simple ( relatively speaking) 2D-Sprite-moving sort of thing.

    I’m grateful that you share your project’s progress with us and manage to keep it both informative and entertaining, even for people like me with no or little experience in 3D-developing. After reading your posts about programming and game design I always take some new ideas with me. Thanks for that!

    By the way, I really hope you are going for an RPG with your project. It reminds me a lot of Morrowind’s large, free to explore landscapes, in a positive sense … only, more lively?

  26. Dnaloiram says:

    As beautiful as that last screenshot was, I get the feeling that it would be tedious if it were to be spread across the entire landscape. Is a greater variety of vegetation planned in the immediate future?

    [Edit]Wait, wait, wait, did you just post this at five in the morning your time? Bad things happen if you anger the sleep god, you know.

  27. TraderRager says:

    What about semi-procedural trees? You start with one of several trunks, which get pre-made branches on semi-random areas of the trees. Other settings (leaf color, shape, healthiness) are decided by the terrain.

  28. TraderRager says:

    Also, is the terrain going to be deformable in the final product, EG. Explosions creating holes and the like? Or is it set in stone once it is rendered?

  29. burningdragoon says:

    Summary of my feelings of the last 3 screens

    1st: I.. guess that’s cool. (edit cuz that doesn’t sound right. Just seems like a lot of grass.)

    2nd: Much better.

    Last: Whoa…

    I wish I was more motivated to do stuff like this >.<

  30. JimminyJoJo says:

    This is looking great, Shamus! A very interesting read as well. Do you plan to turn this into some sort of game or are you solely interested in generating pretty-looking terrain for terrain’s sake?

  31. Jarenth says:

    Shamus, a question occurs:

    You start out with a (mostly) green underground. Then you stick (mostly) green tufts of grass everywhere. But if the grass is a different entity from the ground, why is the ground itself also green?

    Is this for colouring purposes, is it temporary, or does your game take place in a world where dirt happens to be bright green?

    • X2-Eliah says:

      Mossy ground. Also, freshly mowed grass with certain stalks left (at least now that Shamus’s mower works).

      Or, a wizard did it.

    • Shamus says:

      Haven’t I shown off the dirt? I guess I haven’t.

      Grass (the object) only appears where grass (the terrain texture effect) appears. No grass on dirt. The dirt color varies through a spectrum of browns based on the climate. I guess I haven’t shown much dirt in the screenshots.

      • Shamus says:

        And now I see there were a few lines of code for putting dirt on steep slopes. Which I apparently disabled while working on grass.

        I guess that explains why I’m not seeing any, and why none appeared in the screenshots.

      • X2-Eliah says:

        The point is that what’s the actual point of having green under the grass if it blends into a single green blob? There’s no contrast from grass-polygon and grass-texture-on-ground.

        • Dev Null says:

          Well theres _some_ contrast, because of the different shades in the ground texture, and in the grass polygons, but its subtle. So its like multiple layers of grass in a lawn or field full of the stuff, instead of just a couple of clumps growing in the dirt. The effect will probably show better when you move the camera about and get some paralax movement.

          That said, there probably is a place for sparse vegetation, where you actually can see the ground through the blades of grass. Especially on the edges between dirt patches and grass patches. In that case, a greater contrast between the grass shades and the ground ones might be appropriate.

        • Cybron says:

          Because it doesn’t blend into a single blob. Look at the screenshot. You can clearly see the difference between the grass and ground. It creates a varied, textured landscape.

        • Kian says:

          Another issue is that if you put the two quads on brown dirt, the fact that it is a texture slapped on two quads becomes that much more obvious. You would be able to see the straight line on the bottom of the texture against the ground. It looks ugly. By slapping it on ground that has grass texture underneath and is the same color, the distinction is much more subtle, and it helps give the grass ‘height’.

          • Jarenth says:

            Good points all, but it still only partially answers the question of why the ground itself is green in the first place.

            Though ‘I add grass to green underground to emphasise the fact that green underground is supposed to represent grass in the first place’ works for me.

            • aldowyn says:

              Because if it wasn’t you’d see the brown, and you don’t see the brown on a grassy field.

              At least that’s how I’d see it.

            • NeoSonic says:

              The answer is ‘because it looks right’. If you tried to simulate layers of living grass, shorter living grass, trampled living grass, dead grass, moss, leaves, and other random detritus accurately, it would take forever and is likely impossible. So you approximate. The grass tufts provide depth and variance, while the ground texture fills in the gaps. Together they look like real grass to the eye.

              The only thing that counts in the world of graphics is what reads the best.

      • Gravebound says:

        Will there be a an area of blending between empty dirt and grassland where tufts of grass grow in the dirt? Because where I live is lots of rock and barren dirt, but there are still tufts of grass everywhere.

        Or will you be filling the dirt areas with other things?

  32. Erik says:

    Will you be adding animations to the grass and such as well? so its moving in the wind and whatnot? It would look really pretty :)

  33. chabuhi says:

    Hey Shamus, where do I purchase the pre-pre-Alpha pre-order so that I can get exclusive access to your dev journal on this, beta membership when it happens, a discount on the retail release, a plush toy, and so that you can get disgustingly rich while your game is still in pieces?

    Seriously, I want you to be the next Notch. This is the stuff I love most on your blog.

    /suckingup

  34. Alexander The 1st says:

    Huh.

    If you have both grass models, it would be nice to have grass without flowers as well, to add variety. Some sort of flagging, or based on temperature/moisture mapping you’ve done?

  35. LMR says:

    +1 to you for “stone knives and bearskins.”

  36. Rune says:

    At last i found the money to donate to this fine website, that has kept me entertained for 3 years. Money is a little tight for me, but i can in good conscience say that this is the best 20$ i have ever spend (whatever that amounts to in Danish kroner)

    keep up the good work, i hope i can someday visit the states and shake your hand.

  37. asterismW says:

    Maybe it’s just me, but I’m having a really hard time with the perspective. It seems like either the grass is *really* tall, or you have *really* short hills and mountains. I think part of the reason is I can’t decide how close I am to the landscape. The size of the mountains makes me think I’m looking down from pretty high up, but the size and detail of the grass makes me think I’m looking at it from almost eye level. It’s pretty, but I feel like Alice in Wonderland.

  38. Carra says:

    These posts make me want to fire up Visual Studio and learn some OpenGL graphics programming.

  39. When I played Shadow of the Colossus on the PS2, I was mutzing around with the camera one day and found out an clever trick they used to create their grass.

    Essentially they duplicated a section of the terrain geometry and moved it a few degrees up, then repeated three or four times. They then applied – I’m assuming here – the same noise filter to the alpha channels of the duplicated sections. It didn’t really look like grass to be honest, more like moss, but it DID look like vegetation. It looked organic to a level I haven’t seen in a game since.

    Turns out, I’m not the only one who noticed:

    http://rmd.com.au/archives/papervision3d-grass-fur-effect

    http://rmd.com.au/labs/grass/

  40. Paul Spooner says:

    Just wanted to say, “So great!” Of course there’s lots of fiddly stuff you can change, but man it’s looking good. Congratulations on achieving your objectives! Always a pleasure to watch you work.

  41. Joseph Donofry says:

    I’m really truly impressed that you managed to make it look pretty damn good in the end. This whole post is riddled with things I want to learn (either DX or OpenGL) so I can start making some serious games. I’m all for 2D games and all, but I’m not creative enough to make one fun. In 3D, at least there’s a whole world to explore. Anyway, looks great. I look forward to the next post.

  42. Ander the Halfling Rogue says:

    You said you worked on the project itself ahead of the posts and were catching up. Are the posts caught up to what you’re working on NOW yet?
    Cool flowers, by the way.

  43. Maldeus says:

    Oh, wow, that last screenshot is beautiful.

  44. Tili says:

    Very nicely done. Is the source of this project going to available?

  45. Octal says:

    When I saw the first picture with the flowers, I literally went “Oooooo!” out loud. It looks good!

  46. Flamecurse says:

    I’m not much of a programmer but: Wouldn’t it be possible to cut the grass poly count down again by just having two (slightly bigger) triangles instead of full quads? The texture would need a slight adjustment but with a big enough triangle I imagine it would hardly change. I guess the real question is what costs more processing power: Two small triangles or one big one.

    I’m not sure how you’d tackle the flowers at that point though. You wouldn’t have four convenient points at the top to use any more, just one.

  47. Joey Palzewicz says:

    That last photo is absolutely gorgeous, Mr. Young. I’ve saved it as my desktop background, that’s how much I like it.

    It’s looking great, so far. Looking forward to seeing how it turns out!

  48. Neil Roy says:

    When I was mucking about with a terrain project of my own (nothing near as good as yours, just some height mapping etc. For things like grass I used 6 polygons rather than 4 or 8. I found this worked nicely. Like an -X- with a line through it.

    My solution for the edge of the world wasn’t a huge ocean but it was to make opposite edges of the world match so when you walked off the edge of the world you simply wrapped around (like the real world). You can pick a direction and walk endlessly in that direction.

    Battlefield 1942 does something similar. It has a continent in the middle of an ocean on the Wake Island map for example, it then copies the terrain part only (none of the objects or trees on it) for around the edges so if you fly a plane far enough, you will see land off in the distance, you can’t reach the land normally. I managed to get to it with a mod that changed the WW2 planes to jet fighters and seen the shading for buildings etc… on the ground and noted it was the exact same terrain. It’s a great idea if you don’t want an endless ocean.

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>