Search Unity

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Now struggling with collider mesh optimization haha!

    Will get there soon (have the x-axis working)
     
  2. Solistx001

    Solistx001

    Joined:
    Nov 15, 2012
    Posts:
    26
    MinePackage is way too laggy for my liking compared to the code Im using now. Maybe I can reverse engineer the code from MinePackage into the code Im using now for some quick results to get what I need.
     
    Last edited: Nov 23, 2012
  3. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Amazing!
     
  4. Alismuffin

    Alismuffin

    Joined:
    Oct 3, 2011
    Posts:
    100
    So the most recommended learning package is minepackage?
     
  5. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Any ideas how to make billboard grass look wet?

     
  6. Alismuffin

    Alismuffin

    Joined:
    Oct 3, 2011
    Posts:
    100
    use a shader that changes the shiny factor with a spec map and transition from one spec map (Black) to another (white) to add more shininess? I dunno :p
     
  7. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    If you can't alter the texture or shader directly, you could spawn particles ( not sure if you can make those specular? )
     
  8. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    The problem is that the billboards are flat, but real grass is not. In what direction a billboard's normal should look?

    1) If it looks up, the billboard gets the same lighting as the ground below and looks fine, but specular shaders don't work at all.

    2) If the normal is perpendicular to the billboard, you get this:

     
  9. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Have you tried the particles? Maybe very small and bright particles can do the trick?
     
  10. botumys

    botumys

    Joined:
    Apr 16, 2009
    Posts:
    707

    Test with spec + normal map on grass and ground. Adding translucency help.
    To be honest I think that this grass map must be changed to match colors on the ground. (and maybe reduce blades number)
     

    Attached Files:

    Last edited: Nov 25, 2012
  11. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Does it look good from all angles?

    Either the ground has to be green or the grass has to be brown. I came with another solution: I let the grass and the ground be of their natural colors near the camera, but on distance I equalize the colors using modified mipmaps.

     
  12. botumys

    botumys

    Joined:
    Apr 16, 2009
    Posts:
    707
    More or less depending of the lighting.

    Ideas to blend grass and ground:

    - replace flat planes by curved shapes to catch better the light. (you can create a kind of LOD with planes for far and models for near)
    - reduce grass width below to avoid plain color near the ground.
    - maybe replace cutout shader by a transparent shader. In this case you can blend grass and ground using alpha and use a bit of transparency to
    blend grass together. (but can be heavy to render)

    btw, if you send me your ground texture I can adjust grass texture to match colors.
     
  13. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Has anyone thought about using DX11's tessellation displacement to make the grass? It might turn out really ugly though.
     
  14. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Well Nvidia showcased this on Top Tier 2010 hardware.



    Jump to 1 minute in.
     
  15. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    ^ That's what alexzzzz should be using. Come on alex, should take 5 mins to add in :p
     
  16. Lordinarius

    Lordinarius

    Joined:
    Sep 3, 2012
    Posts:
    94
    I am working to make sphere world made with minecraft cubes

    I made sinusoidal for now . Working on it :)


     
  17. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148

    That looks..... Strange
     
  18. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    Thanks to this thread, we have had colored lights for over a year now. However, the lights were predetermined for a handfull of blocks. We were seriously underutilizing the power of the light engine.
    But last night, I added the ability to make any color light the user wants:



    Here you can see the crafting table on the left. To 1 snow block, I am adding 3 red and 3 blue. So a purple snow comes out.
    Then you can place that on the ground:


    and you get the full purple light. If I instead of 3 red and 3 blue, I just added say 1 red, I would get a less strong red light. Green + red would make yellow, green + blue would make cyan, etc.

    So by combining red, green and blue, up to 3 each, the user can make any one of 64 light colors. Neato.
     
  19. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Yeah this thread is pretty kickass.

    Good job GoldBug
     
  20. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    hey thanks for sharing your script. but can u explain me why monodev spits me out some errors an the game didnt start

    "unity Monobehaviour has unknown format!"

    my unity version is 3.4.2!
     
  21. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    That is because he said he doesn't know how to write one...... And that one doesn't work like he said....
     
  22. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    go on his YT Channel . There is the Working Source. In Unity 4.0.0 it works like a charm but in 3.4.2 not. But i would not change my version for the next time.
     
  23. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    I'd suggest pming him as your posts will get drowned out here :)
     
  24. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I'm trying to write a shader of raindrops or thin water streams running down the walls

     
    Last edited: Dec 1, 2012
  25. Joel-Huenink

    Joel-Huenink

    Joined:
    Dec 3, 2012
    Posts:
    7
    Alexzzzz I am very impressed with your continued progress. Your effect looks good you just might need to tweak the textures.
     
  26. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Can we talk about Mesh Colliders?

    What I mean is, what are the alternatives to using a MeshCollider? I guess if it's truly a block-mesh world you could write the physics easily enough based upon the blocks that are in memory versus the player position and spew out a bunch of raycasts based on that.

    Any suggestions? Anything in-between the slowness of using a meshcollider and writing ones own physics? What if the meshes aren't true blocks?
     
  27. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    I would highly suggest using mesh colliders just with efficient mesh optimisation scripts. The general laggyness/jerking will pretty much disappear.

    For example My mesh colliders

    BEFORE optimisation -------> (2836 Verts, 1418 Triangles)

    AFTER optimisation -------> (244 Verts, 122 Triangles)

    And these colliders were only really optimized about 1/4 of the way
     
  28. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    I completely removed mesh Colliders in our implementation. They are just painfully slow when instantiating the chunk game objects, consume unnecessary memory and frankly they are overkill given the rectilinear nature of the world.

    They also don't work as good as you would like, for example, you would want your character to be able to walk a little out of the edge of a block, so that you can place a block below your feet and build a roof. But the regular character controller is a capsule, which makes this a bit awkward.

    Instead, I implemented sweep AABB collision detection and clipping. This MUCH faster, and works beautifully. You can walk over the edge until your box no longer touches the floor. I believe MC does this too. Mind you, this is painful to implement, but works a lot better than mesh colliders.




     
  29. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    Something like this?:



    I read out some of Deni35´s code and get it to work.
    Just change somthing of your favorite in the GenerateBlock funktion to check each Layer and add some stuff.
    Here is my Try to add Trees with the TreeGenerator Class, Cacti´s and some Coal and Flowers...

    Some Decorations are Buggy (Trees so far.) because the Chunk doesnt regenerate and the leaves are cuttet on each Chunk to Chunk border.

    Code (csharp):
    1.  
    2.     private void GenerateBlock(int worldX, int worldY, int worldZ, int deep) {
    3.     Block block = GetBlock(worldX, worldY, worldZ, deep);
    4.        
    5. if(block == grass){
    6.  
    7. if (Random.RandomRange(1, 100) >= 97)
    8.             {                      
    9.             map.SetBlock(new BlockData(redflower), worldX, worldY+1, worldZ);
    10.             map.SetBlock(new BlockData(grass), worldX, worldY, worldZ);
    11.             }
    12.            
    13.             else if (Random.RandomRange(1, 200) == 78)
    14.             {
    15.                 treeGenerator = new TreeGenerator(map);
    16.                 treeGenerator.Generate(worldX - 3,worldZ - 3);
    17.                
    18.                 //Vector3i? point = new Vector3i(worldX,worldY,worldZ);
    19.                 //map.SetBlockAndRecompute(new BlockData(), point.Value);
    20.  
    21.             }
    22.             else
    23.                 {
    24.                 map.SetBlock(new BlockData(grass), worldX, worldY, worldZ);
    25.                 }      
    26.            
    27. }
    28.    
    29.        
    30.        
    31. else if(block == sand){
    32.             if (Random.RandomRange(1, 500) == 99)
    33.             {
    34.                 cactiGenerator = new CactiGenerator(map);
    35.                 cactiGenerator.Generate(worldX,worldZ);
    36.                
    37.                 //Vector3i? point = new Vector3i(worldX,worldY,worldZ);
    38.                 //map.SetBlockAndRecompute(new BlockData(), point.Value);
    39.  
    40.             }
    41.             else
    42.                 {
    43.                 map.SetBlock(new BlockData(sand), worldX, worldY, worldZ);
    44.                 }      
    45.            
    46.         }
    47.        
    48.        
    49. else if(block == stone){
    50.             if (Random.RandomRange(1, 100) >= 77)
    51.             {
    52.  
    53.                
    54. int random = Random.Range(1,10);
    55. for(int i=0; i<random; i++) {
    56. map.SetBlock(new BlockData(coal), worldX, worldY-random, worldZ);
    57.                 }              
    58.                 //Vector3i? point = new Vector3i(worldX,worldY,worldZ);
    59.                 //map.SetBlockAndRecompute(new BlockData(), point.Value);
    60.  
    61.             }
    62.             else
    63.                 {
    64.                 map.SetBlock(new BlockData(stone), worldX, worldY, worldZ);
    65.                 }      
    66.            
    67.         }      
    68.         else{
    69. if(block != null) map.SetBlock(new BlockData(block), worldX, worldY, worldZ);
    70.  
    71.     }}
    72.  
    I love Denis code :-O Its realy easy to add some stuff on spezial Layers. Only Cactis grown on sand and so on...
     
  30. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Hmm interesting.

    Any idea where I could start with AABB collision detection?
     
  31. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    Read this paper.
    It explains collision detection and movement clipping very well but for a sweep ellipsoid. I hope you paid attention in math :)

    Sweep ellipsoid is not what you want, but I found that paper very good for understanding how things work. After that, it is much easier to understand and implement the simpler AABB-AABB collision detection.
     
    Last edited: Dec 4, 2012
  32. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    If anyone wants to try a demo of our game for pc or mac, you can get it here.

    I get 1000 fps in my laptop on default settings (that is not a typo). Enjoy.
     
  33. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    On second though :p

    Haha
     
  34. Joel-Huenink

    Joel-Huenink

    Joined:
    Dec 3, 2012
    Posts:
    7
    "Thirty Days to Die" (working title) is an open world RPG, Tower Defense, Shooter hybrid set in the post-apocolyptic near future. Blending Minecraft, Left4Dead and Doom in games and I am Legend, Mad Max and 28 Days Later in movies.

    That said, we are looking to partner with one of you Unity/Minecraft gurus and either license your engine work or share royalties for some code, etc. My studio has shipped 4 titles, and all members have shipped multitudes of AAA games. Send me a PM if you are interested.
     
  35. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    Yeah, lol, the paper does look intimidating. It did take me a long time to get collision detection right (and there is still a bug out there), but the performance gains, and improved behavior were very much worth it.

    But maybe you don't need it. We are making the game for mobile, so performance is a lot more important for us, for desktops, optimized mesh colliders should be good enough.

    The other solution you might want to try is creating box colliders around the player for the solid blocks. As the player walks, you can create new box colliders for the blocks closer to you, and destroy the ones that you left behind. This has the advantage that you are not paying for the big latency that happens every time you create a large mesh collider, plus box colliders are generally faster than mesh colliders.

    The only problem with this approach is that it does not scale so well when you start adding mobs. Also, when we were trying this approach, sometimes if the player moved too fast, or if the stars aligned right, the player would fall through the terrain.
     
  36. XavLar

    XavLar

    Joined:
    Feb 14, 2012
    Posts:
    143
    For those who are experiencing Pixel Bleeding, I am glad to present you a fix for that bug! Just change your Image import settings to the one's below and presto! Fixed :)

    \






    (Results may vary)
     
  37. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    If someone tryed out Denis code i need some help to find the blockname where im looking at..

    Player Building Script:

    Code (csharp):
    1.  
    2. ...
    3.  
    4.     private Vector3i? GetCursor(bool inside) {
    5.         Ray ray = new Ray(cameraTrans.position, cameraTrans.forward);
    6.         Vector3? point =  RayBoxCollision.Intersection(map, ray, 10);
    7.         if( point.HasValue ) {
    8.             Vector3 pos = point.Value;
    9.             if(inside) pos += ray.direction*0.01f;
    10.             if(!inside) pos -= ray.direction*0.01f;
    11.             int posX = Mathf.RoundToInt(pos.x);
    12.             int posY = Mathf.RoundToInt(pos.y);
    13.             int posZ = Mathf.RoundToInt(pos.z);
    14.             Vector3i? cursorposition = new Vector3i(posX, posY, posZ);
    15. //My first try!
    16.             Debug.Log(map.GetBlock(2,54,2).block); // try to find out the name of the block in the world to build some inventory refills
    17. //only "Cube" is written to the Log each time.
    18.             return cursorposition;
    19.         }
    20.         return null;
    21.     }
    22.  
    23. ...
    24.  


    best regards
     
  38. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Yeah I thinking abou your second option, but mobs could really screw that up.

    I'll probably go ahead with AABB collision detection, apart from the paper any ideas where to start code wise?

    Thanks
     
  39. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I've switched from Strumpy Shader Editor to plain text shaders. It turned out it's much easier to write shaders by myself, and also there are things impossible to do in SSE.

    Here is a replacement shader than visualizes light values, stored in one of the components of vertex colors (alpha in this case.)




    Code (csharp):
    1.  
    2. Camera.main.SetReplacementShader(debugShader, "RenderType");
    3.  
    PHP:
    Shader "SunLightDebug"
    {
        
    Properties
        
    {
            
    _MainTex ("Base RGB"2D) = "gray" { }
        }

        
    SubShader
        
    {
            
    Tags
            
    {
                
    "Queue" "Geometry"
                "IgnoreProjector" 
    "True"
                "RenderType" 
    "Opaque"
            
    }

            
    Cull Back
            ZTest LEqual
            ZWrite On
            AlphaTest Off

            CGPROGRAM
                
    #pragma surface surf Debug nolightmap novertexlights
                #pragma target 2.0

                
    sampler2D _MainTex;

                
    struct Input
                
    {
                    
    float4 color COLOR;
                    
    float2 uv_MainTex;
                };

                
    struct SurfaceOutputX
                
    {
                    
    half3 Albedo;
                    
    half3 Emission;
                    
    half3 Normal;
                    
    half Specular;
                    
    half Alpha;
                };

                
    void surf(Input inputinout SurfaceOutputX output)
                {
                    
    half intensity input.color.a;
                    
    intensity round(intensity 15) / 15;

                    
    half separator frac(input.color.15);
                    
    half halfWidth 0.05;
                    
    separator step(0.5 halfWidthseparator) * (step(0.5 halfWidthseparator));

                    
    output.Albedo =  intensity 0.5 separator;
                }

                
    half4 LightingDebug(SurfaceOutputX shalf3 lightDirhalf atten)
                {
                    
    half4 result;
                    
    result.rgb s.Albedo;
                    
    result.1;
                    return 
    result;
                }
            
    ENDCG
        
    }

        
    SubShader
        
    {
            
    Tags
            
    {
                
    "Queue" "AlphaTest"
                "IgnoreProjector" 
    "True"
                "RenderType" 
    "TransparentCutout"
            
    }

            
    Cull Off
            ZTest LEqual
            ZWrite On

            CGPROGRAM
                
    #pragma surface surf Debug nolightmap novertexlights
                #pragma target 2.0

                
    sampler2D _MainTex;

                
    struct Input
                
    {
                    
    float4 color COLOR;
                    
    float2 uv_MainTex;
                };

                
    struct SurfaceOutputX
                
    {
                    
    half3 Albedo;
                    
    half3 Emission;
                    
    half3 Normal;
                    
    half Specular;
                    
    half Alpha;
                };

                
    void surf(Input inputinout SurfaceOutputX output)
                {
                    
    half intensity input.color.a;
                    
    intensity round(intensity 15) / 15;

                    
    half separator frac(input.color.15);
                    
    half halfWidth 0.05;
                    
    separator step(0.5 halfWidthseparator) * (step(0.5 halfWidthseparator));

                    
    output.Albedo =  intensity 0.5 separator;

                    
    half clipThreshold tex2D(_MainTexinput.uv_MainTex).0.1;
                    
    clip(clipThreshold);
                }

                
    half4 LightingDebug(SurfaceOutputX shalf3 lightDirhalf atten)
                {
                    
    half4 result;
                    
    result.rgb s.Albedo;
                    
    result.1;
                    return 
    result;
                }
            
    ENDCG
        
    }
    }
     
    Last edited: Dec 5, 2012
  40. Joel-Huenink

    Joel-Huenink

    Joined:
    Dec 3, 2012
    Posts:
    7
    Alexzzzz do you have an email address or way I can contact you? I'm interested in licensing your rendering code or retaining your programming services if possible. Thanks,
    Joel
     
  41. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    goldbug,

    did you create a bounding volume for each visible block?

    each visible face of a block?

    each chunk-mesh?

    thanks,
    foam
     
  42. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    BTW, for those looking into collision detection, I strongly recommend the book "Real-Time Collision Detection." I read through parts of it today and it is extremely good. It is a very clear presentation and I would buy that book and use it before even bothering with browsing through the net for other explanations. Worth every penny.
     
  43. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    I get into some trouble while generation some water and other meshes without colliders.
    is there a way to remove the meshcollider from some points of a mesh?
    because some times a chunk is filled with water and other blocks like landscape or trees,.... and the hole mesh has a meshcollider and the player can walk over water like jesus.



    i use denis code for experimentations.
     
  44. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Skip the water when generating colliders.
     
  45. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    you have the coordinates of a character, you know how big he is and how much he is moving on every frame. This is enough to determine which blocks he could be possibly hitting, so you run an AABB-AABB test for each solid block that he can be hitting. For a 1.8 height character, he could normally be hitting one of 12 blocks or less, so you only have to test for those.
     
  46. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    I second that. I could not remember the name of the book, but it is excellent. It is scanned in the google libraries btw.
     
  47. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    it's on Safari Online as well for those who have access to it.
     
  48. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Ok, thanks.

    I am going to give this a shot. I really don't want to write my own physics engine but the CollisionMeshes are killing my frame rates and the material in "Real-Time Collision Detection" looks pretty straight forward. For each frame: take the player's position and calculate an AABB volume for them, then calculate an AABB volume for each nearby block, then use plane intersection to figure out if they collide, if they do, adjust the physics accordingly. Or something like that.

    Or perhaps I'll try to optimize the mesh first.
     
  49. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Anyone have any suggestions for keeping frame rates up when creating meshes? I have my actual noise calculations and mesh calculations off in other threads but when I actually instantiate a mesh it drops the frame rates for a tiny bit.

    I'm thinking that it might be because I have a ton of work spawned off into the ThreadPool, not leaving much CPU left for the main Unity thread. I'd like to reserve one core just for Unity but I'm not really sure if that's possible. Is there a way to ensure that the main Unity thread has the highest priority and whatever I'm doing in the other threads is only handled on an "if possible" basis?
     
  50. soulreafer

    soulreafer

    Joined:
    Nov 6, 2011
    Posts:
    28
    I get it :) but i played arround with layers so water ignores the player collider

     
Thread Status:
Not open for further replies.