Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2006
    Location
    Lubbock, Texas
    Posts
    345

    Terrain R&D Session 2 ~ Pt. 13 issue.

    Hi guys,

    Something has occured to my patching around Session 2 Pt. 13. I am now getting this:

    Click image for larger version. 

Name:	Fail.jpg 
Views:	89 
Size:	824.2 KB 
ID:	71665

    I didn't notice this until I jacked up the height in part 17 or 18. Any one have an idea as to if i even need to worry about this issue at this point, or should I just keep on going?

    Some advice would be appreciated. Thank you.

    David

    I just found the neatest thing: VS 2010's "Find usages" function. I had noticed that it's only when my Spacing is set above 1 that this issue occurs so I used "Find usages" to look at all the places Spacing is used in calcs and then exported it to a .txt file:

    Search target
    _CodeBase.Demos.TerrainPatch.Spacing:float
    Found 27 usages in solution
    <Lee'sTestingFrameworkUnityProject> (21 items)
    Assets (21 items)
    _CodeBase (21 items)
    DemoFramework (21 items)
    Demos (21 items)
    TerrainGenerator.cs (1 item)
    (23,35) var fs = TerrainPatch.Spacing;
    TerrainPatch.cs (20 items)
    (33,63) position = new Vector3(value.x * (Size - 1) * Spacing,
    (35,63) value.z * (Size - 1) * Spacing);
    (41,33) get { return Size * Spacing; }
    (75,39) var offset = (Size - 1) * Spacing / 2f;
    (83,76) var height = TerrainDemo.terrain.GetSmoothHeight(x*Spacing - offset + Position.x,
    (84,76) z*Spacing - offset + Position.z,
    (87,54) vertices.Add(new Vector3(x * Spacing - offset, height, z * Spacing - offset));
    (89,38) var u = (x * Spacing) / ((Size - 1) * Spacing);
    (90,38) var v = (z * Spacing) / ((Size - 1) * Spacing);
    (99,40) var posX = x * Spacing - Spacing / 2;
    (104,49) if (posX > (Size - 1) * Spacing)
    (105,49) posX = (Size - 1) * Spacing;
    (109,63) if (posX == 0 || posX == (Size - 1) * Spacing)
    (114,76) var h1 = TerrainDemo.terrain.GetSmoothHeight(x*Spacing - Spacing - offset + Position.x,
    (115,78) z * Spacing - offset + Position.z, SmoothingIterations);
    (116,76) var h2 = TerrainDemo.terrain.GetSmoothHeight(x*Spacing - offset + Position.x,
    (117,78) z * Spacing - offset + Position.z, SmoothingIterations);
    (122,77) vertices.Add(new Vector3(posX - offset, height, z * Spacing - offset));
    (124,54) var u = posX / ((Size - 1) * Spacing);
    (125,38) var v = (z * Spacing) / ((Size - 1) * Spacing);

    Even though I'm being told to keep watching I thought I'd throw this Find Usages thing out there for anyone that didn't know about it. It seems REALLY handy.
    Last edited by Barad_Dur; 05-06-2011 at 01:24 PM.
    I USED the search function and couldn't find what I needed!

  2. #2
    Join Date
    Dec 2002
    Location
    Virginia Beach, VA
    Posts
    861
    Keep watching we address this problem.
    “little expense has been spared to give the impression that no expense has been spared.” - Douglas Adams

  3. #3
    Join Date
    Jan 2010
    Location
    Buenos Aires, Argentina
    Posts
    148
    Check if you didnt mixed a .z for a .y somewhere. That happens a lot when you build vector2 out of vector3.

  4. #4
    Join Date
    Jun 2006
    Location
    Lubbock, Texas
    Posts
    345
    Well, I have begun session 3 and I am still getting really weird problems with my terrain when my "PatchVertexSpacing" is anything but 1.
    When it is set to 2 it looks something like this: Click image for larger version. 

Name:	fail_1.jpg 
Views:	73 
Size:	1.16 MB 
ID:	71710

    When it is set to 1 it seems to look fine:Click image for larger version. 

Name:	NoFail.jpg 
Views:	72 
Size:	1.69 MB 
ID:	71711

    I can't help but wonder if this is in the GetSmoothHeight method in the TerrainGenerator. I was thinking that it was the CreateMesh method but Lee went back through that near the end of Session 2 and it still didn't fix my little red wagon. Could someone verify that I'm not missing something in GetSmoothHeight method? It would really help me out to advance. Thank you.

    Code:
            public float GetSmoothHeight(float x, float z)
            {
                var height = GetHeight(x, z);
    
                var fs = int.Parse(Config.Setting["PatchVertexSpacing"]);
                var hs = fs/2;
                var ul = GetHeight(x - hs, z + fs);
                var ur = GetHeight(x + hs, z + fs);
                var lt = GetHeight(x - fs, z);
                var rt = GetHeight(x + hs, z);
                var ll = GetHeight(x - hs, z - fs);
                var lr = GetHeight(x + hs, z - fs);
    
                var avgHeight = (ul + ur + lt + rt + ll + lr)/6;
    
                var iterations = int.Parse(Config.Setting["SmoothIterations"]);
    
                var adaptiveIteration = (int)Math.Abs(height - avgHeight);
                if (adaptiveIteration > 5)
                    adaptiveIteration = 5;
    
                for (int i = 0; i < iterations + adaptiveIteration; i++)
                {
                    height = Utils.Lerp(height, avgHeight, 0.2f);
                }
    
                return height;
            }
    Last edited by Barad_Dur; 05-16-2011 at 12:46 PM.
    I USED the search function and couldn't find what I needed!

  5. #5
    Join Date
    Apr 2009
    Location
    Rochester, MN
    Posts
    179
    This is what I have for rt
    var rt = GetHeight(x + fs, z);

  6. #6
    Join Date
    Jun 2006
    Location
    Lubbock, Texas
    Posts
    345
    Seridaq,

    I think I might have changed that during the Session 2 Errata videos but it's highly possible that It was similar code somewhere else that I changed. When I get back to work Monday I will look to see if your suggestion is indeed what is going on.
    I USED the search function and couldn't find what I needed!

  7. #7
    Join Date
    Jun 2006
    Location
    Lubbock, Texas
    Posts
    345
    Seridaq,

    Well, I checked my code this morning and sure enough you were right so I changed the code, did a build and fired up the terrain project in Unity and . . . nothing changed so this wasn't it at all. But, faulty code needs to be corrected even if it doesn't fix the problem at hand so thank you for catching that issue with my code.

    David.
    I USED the search function and couldn't find what I needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •