XNA Creators Club Online
Page 5 of 5 (103 items) < Previous 1 2 3 4 5
Sort Posts: Previous Next

Terrain LOD Again

Last post 09-05-2008 10:58 PM by DimX. 102 replies.
  • 08-15-2008 2:57 AM In reply to

    Re: Terrain LOD Again

    I had a chance to play with your code today to try to figure out the weird shadow problem that still exists with the code.

    After a few hours I have narrowed the problem down to a few lines of code.  But the problem area is perplexing.

    I first looked over the shader code.  It seemed OK. Then I moved onto the generation of the normals, because I came to believe that was in error.  But that too, was OK.  I generated the same exact normal map as you do.

    So I added the following bit of code to your LoadContent class right after the creation of the new quadterrain and subsequent texture save to "C:\normalData\test.png"

     

    Texture2D test = Content.Load<Texture2D>("test");  
    q.TerrainShader.Parameters["NormalTexture"].SetValue(test); 

     

    Viola it worked!  But the question is why?  What is the Content loader doing different with the texture vs. what you did to generate it?  I couldn't come up with an answer, but I need to get back to my code.

  • 08-15-2008 4:58 AM In reply to

    Re: Terrain LOD Again

    Hey cool! It's great you got it working...

    ..but...

    ...what the heck? I wonder why it would do that? That makes no sense.

    Here's the relevant texture generation code:

    //Define texture  
    private Texture2D normalTexture;  
     
    //...  
     
    //Constructor  
    normalTexture = new Texture2D(g, heightMap.Width, heightMap.Height, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Color);  
    //Color array  
    Color[ normalData = new Color[heightMap.Width * heightMap.Height];  
     
    //...  
     
    //Generate the normal data array (this is done for every pixel)  
    normalData[x + y * terrainHeight] = new Color(texVector);  
     
    //...  
     
    //After normalData has been filled:  
    normalTexture.SetData<Color>(normalData);  
    normalTexture.GenerateMipMaps(TextureFilter.Anisotropic);  
    //Add the normal texture to the shader  
    TerrainShader.Parameters["NormalTexture"].SetValue(normalTexture); 

     

    Maybe someone with more XNA experience could tell us why the above would have different results on Gorky's graphics card when compared to loading the exact same texture via the content pipeline, after it had been saved using Texture2D.Save?

  • 09-05-2008 10:58 PM In reply to

    Re: Terrain LOD Again

    Not sure if you've already discovered the problem, but it seems to be caused by mipmaps. If you set the mipmap level to 1, TextureUsage to None and skip the GenerateMipMaps call then it'll work the same way as with the loaded PNG texture.
Page 5 of 5 (103 items) < Previous 1 2 3 4 5 Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG