Announcement

Collapse
No announcement yet.

The Quest to combine Texture Atlasing and Landscape painting.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    The Quest to combine Texture Atlasing and Landscape painting.

    Hey there folks

    I've been working on my survival game Atajrubah for a while now, one of the things that I was hoping to see improved was the landscape painting. In particular I was hoping that I wouldn't run into the 4 textures per component limit like I had in UDK. Alas I did and so have others I see, like most folks I've been floundering about trying to get a texture atlas working for this purpose.

    I was having a tough time until Tappy Chicken was released, I dived into the project once it was downloaded and saw that they were using a bit of atlasing for the eggs. So I hacked out the material nodes responsible for this functionality and took some time to figure out how they work. I figured that I should be able to get them working with the material setup that I was using to paint my terrain.Below is the setup that I've been using and the results.

    [Landscape Material Setup]


    [Result]


    I took the nodes that were getting the job done in the egg material from tappy chicken and put them into a material function called TextureAtlas. I made some minor changes below.

    [Material Function with Modified Tappy Chicken Nodes]


    [...Continued]


    This is what the material function looks like when used in my material, following that is the setup integrated with the material setup I had going on before.

    [Current Material Function Outputs]


    [Modified Landscape Material Setup]


    Does it work though ? Well kind of....
    Once I compiled the shader this is the result I get...

    [Result]



    I think I understand why this is happening. The landscape coordinates are at 8192 to match the size of my atlas(a bit big yes but everything loads up just fine and theres no noticeable drop in performance). As far as I can tell its taking the individual outputs from my TextureAtlas material function and scaling them from 1024 to fit those coordinates. Resolution aside for a moment does it work ? ... Yes it does.

    [More than 4"textures per component]


    If I'm not mistaken what I need to do next is find a way of tiling the outputs from the material nodes before sending them into the blend nodes. How exactly to get this done is kind of beyond me at the moment. Most of my technical experience is on the C++ side of things and I'm still getting used to the updated material editor. I was thinking about something along the following lines:

    [Proposed AtlasFunction Output modifier]


    It would be super awesome to get any help from the community on this. I'm sure that there are plenty of folks on here that would put this kind of thing to good use
    Is there anyone out there that can help make this happen ?

    Let me know your thoughts

    - MrNexy

    #2
    AFAIK we need access to the custom node + tex2dgrad which we don't have.

    https://forums.unrealengine.com/show...exture-atlases

    That thread discusses also.

    This shows the UE3 way which UE4 does not yet support: http://oliverm-h.blogspot.se/2013/04...e-atlases.html

    I vaguely remember the Custom node being on its way though. Maybe in 4.3

    Your 8k terrain is huge by the way. Framerate is one thing, but there is also memory. I have done 8k terrains, and if you run this in game (not editor game) and you type Stat Memory, you will see a pretty huge memory load. Due to the collision data of the ~67 million triangle object. You can step down collision complexity, but if you got items or such that can lay on the ground it will be obvious. Plus you will have huge problems filling this giant space up with objects also (trees, rocks, etc.).

    Comment


      #3
      Hourences: the Custom node is there. the code editor in it is only one line of text though which is ****
      not sure how much stuff it does currently
      Follow me on Twitter!
      Developer of Elium - Prison Escape
      Local Image-Based Lighting for UE4

      Comment


        #4
        Yeah that is what I meant. I know it is there but I can't figure out how to make it do what the UDK one does.

        I don't write HLSL or such though, maybe there is a way.

        Comment


          #5
          well I tried three options of a one liner and it worked
          return 0;
          return 0.5;
          return 1;
          produced a black, gray and white color respectively
          didn't try anything more complex but I'd assume separating lines only with semicolons should work. a pain to work with though
          Follow me on Twitter!
          Developer of Elium - Prison Escape
          Local Image-Based Lighting for UE4

          Comment


            #6
            Thanks for taking the time to respond to my post guys!

            @Hourences : That was a little overambitious on my end I guess hehehe The terrain itself is based on a 2048 height map, I did indeed run Stat Memory and the texture memory was ridiculous (something like 300-400 MB). I took the time to create a new map and re-imported the terrain,scaled it a little differently than before and made a new terrain material.

            I ended up packing 8 textures (4 grey-scale images and their normals) into 4 files with space for 2 more.Its been a little bit of work figuring out how to rebuild the color and normal maps but it looks like I'll get quite a bit of variety out of what I've got, if I mix things about I could potentially end up with 100 variations. That aside after having done this my texture memory footprint dropped to 94.3 MB. Thanks for that heads up !

            Populating a large landscape with enough foliage meshes and objects to make it interesting,while keeping things running efficient is definitely an area of concern. Thus far I've been extensively using LOD and I'm certain that I'll learn some great tips and tricks from your solus videos

            Comment


              #7
              Ah if it is a 2k height map that is not too bad. Neither is 400 mb memory. If you consider that most gaming pcs and next gen consoles have 8 or so GB in memory, you can take 400 for a terrain. According to my tests earlier it was really the collision data that had a hit on memory and was the biggest concern.

              Solus was meant to be large and open, but I had to scale down because of the difficulties in making such big worlds... That is why I now got islands, means allow me to have small areas surrounded by emptiness. I am not saying it is impossible to do large open worlds, but it is definitely not the strongest point of the engine, and the overhead and risk it brings along is too big imo to be worth it.

              Lod wise foliage is special. I have not tried this, but I assume the foliage will either never lod, or it will lod in groups. Foliage is instanced, it batch renders parts together. So it can't lod individual objects within a batch. It will likely lod the entire group at once or none of it.
              And those groups would have to be pretty big, to lower the total number of groups that exist in the level. A max draw distance would have to be set also. And even then... Just grasses alone already is going to result in probably thousands if not tens of thousands of clusters on such a big scale...

              Streaming levels/world browser may help, but standing on a mountain and overlooking the whole area would still result in the above problems.

              It very quickly all gets out of hand.

              Comment


                #8
                Ah if it is a 2k height map that is not too bad. Neither is 400 mb memory. If you consider that most gaming pcs and next gen consoles have 8 or so GB in memory, you can take 400 for a terrain. According to my tests earlier it was really the collision data that had a hit on memory and was the biggest concern.
                Thats good to know My collision data (navigation data ? ) is around 200 , this is definitely an area of concern moving forward.

                Solus was meant to be large and open, but I had to scale down because of the difficulties in making such big worlds... That is why I now got islands, means allow me to have small areas surrounded by emptiness. I am not saying it is impossible to do large open worlds, but it is definitely not the strongest point of the engine, and the overhead and risk it brings along is too big imo to be worth it.
                You're absolutely right! I've thought about scaling things back on numerous occasions and especially when I've run into technical issues on the UE4 side. Its still early days I suppose and there are plenty of improvements that are likely to only be implemented in versions leading up to 4.4.

                Lod wise foliage is special. I have not tried this, but I assume the foliage will either never lod, or it will lod in groups. Foliage is instanced, it batch renders parts together. So it can't lod individual objects within a batch. It will likely lod the entire group at once or none of it.
                And those groups would have to be pretty big, to lower the total number of groups that exist in the level. A max draw distance would have to be set also. And even then... Just grasses alone already is going to result in probably thousands if not tens of thousands of clusters on such a big scale...

                Streaming levels/world browser may help, but standing on a mountain and overlooking the whole area would still result in the above problems.

                It very quickly all gets out of hand.
                You're right about the foliage LOD as far as I can tell. Thankfully I won't be creating vast grasslands or tall mountainous peaks, granted that does mean that I will have to be extra careful. Things like cluster count,size and draw distance are certainly a concern. I've been pondering how to best use streaming levels in open outdoor spaces, subterranean applications of level streaming work very well as you demonstrated in your video walkthrough of Solus.

                I'm interested to see where they take things with the world browser and how it will impact creating large open worlds in a more manageable way.

                Comment


                  #9
                  Current Landscape Material Update

                  Hey there folks .

                  Just wanted drop by with an update on my current material setup.
                  I've gone with the texture packing route and by packing 4 gray scale textures into the R,G,B and Alpha channels.For the normals I had to take a more straight forward approach by simply using one texture per normal. I would have used the same packing for the normals but their quality suffers from it, I think it may have something to do with the way textures are handled during compression.

                  In addition to the 4 original textures I was able to create 6 new textures and normals by recombining the original textures and their normals. With 5 color variations I ended up with a palette of 50 colors.





                  The shader is a mess of strings but modular and not too difficult to make adjustments to one step at a time. The shader compilation count and time can be long (around 250,000 in my case) but once everything is compiled and you're not making any changes to the shader you're good to go I haven't noticed any performance hits or increase in memory usage for textures or shaders even with all of the different layers in use.

                  Let me know your thoughts ^^

                  -MrNexy

                  Comment


                    #10
                    That is pretty crazy. We did something similar for Sol but not quite so much of it. Along the same lines, you can pack two normal maps into one Dxt5 texture by breaking each into just rg and using the node derivenormalZ inside of the material to regenerate the B channel.

                    I am curious what the pixel shader cost is. At some point these 'memory savings tricks' can become expensive.
                    Ryan Brucks
                    Principal Technical Artist, Epic Games

                    Comment


                      #11
                      Hey there RyanB

                      Along the same lines, you can pack two normal maps into one Dxt5 texture by breaking each into just rg and using the node derivenormalZ inside of the material to regenerate the B channel.
                      I'll get that integrated into my current shader, its probably more effective than what I've been using which is the Append Vector node.

                      I am curious what the pixel shader cost is. At some point these 'memory savings tricks' can become expensive.
                      At the moment I'm recompiling the shaders after some changes ,there are 20/50 or so layers compiled so far and the pixel shader memory is around 9 MB engine. I'll get some more layers painted after compilation and see how high it goes. What is rough is the navigation memory hehehe.

                      Comment


                        #12
                        No append vector is almost a free operation so it is faster. For derive normal z, the shader must solve the z value for each pixel using the Pythagorean theorum. It saves texture samples but adds gpu rendering cost. Only necessary if you are hitting some kind of texture sample limit. It doesn't really save memory either since two dxt1 textures are the same as a dxt5.

                        What I forgot to mention was how you would be packing two normals into a single dxt5. Red and green are normal 1, blue and alpha are normal 2.
                        Last edited by RyanB; 06-07-2014, 02:22 PM.
                        Ryan Brucks
                        Principal Technical Artist, Epic Games

                        Comment


                          #13
                          Originally posted by MrNexy View Post

                          At the moment I'm recompiling the shaders after some changes ,there are 20/50 or so layers compiled so far and the pixel shader memory is around 9 MB engine. I'll get some more layers painted after compilation and see how high it goes. What is rough is the navigation memory hehehe.
                          Actually I meant the number of instructions. The memory matters but is of lesser concern than the number of instructions the material does. At the top of the material editor viewport, it should say something like "250 instructions with dynamic lighting" and then another line listing a bigger number for static light maps.
                          Last edited by RyanB; 06-07-2014, 02:42 PM.
                          Ryan Brucks
                          Principal Technical Artist, Epic Games

                          Comment


                            #14
                            Actually I meant the number of instructions. The memory matters but is of lesser concern than the number of instructions the material does. At the top of the material editor viewport, it should say something like "250 instructions with dynamic lighting" and then another line listing a bigger number for static light maps.
                            That is very handy to know, thank you.
                            These are the stats for the material, they add up to 207 instructions thus far (at first glance).

                            Code:
                            Info Texture samplers: 6/16
                            Info Base pass shader with static lighting: 99 instructions
                            Info Base pass shader with only dynamic lighting: 75 instructions
                            Info Vertex shader: 33 instructions
                            Last edited by MrNexy; 06-07-2014, 04:24 PM.

                            Comment


                              #15
                              That instruction count seems pretty low to me. Anything under 100 is viable on mobile actually although sometimes we have to go further and check fullyrough and disable the directional lightmaps. That usually seems to cut another 20-30% although if not on mobile there is usually no reason to go so far.

                              You don't need to add the instruction counts. It's just 99 if you have lightmaps but only 75 if you have only dynamic lighting.
                              Ryan Brucks
                              Principal Technical Artist, Epic Games

                              Comment

                              Working...
                              X