Menu

TGLBumpmapHDS.PreparingData problem

Help
lnebel
2015-01-08
2015-01-09
  • lnebel

    lnebel - 2015-01-08

    A few months ago I and other users (Vu, Rikke) suggested some changes to TGLBumpmapHDS to fix a shading problem. The problem causes striping and other effects. The shaded terrain demo works but in my project the problem is still there? I am not sure exactly why but the changes originally suggested by Vu and modified by me works. Here is a copy of the method that makes my project work properly.

    The problem is not related to the problem in GLROAMPatch described in another thread

    The attached images show the difference in my project before and after replacing the method PreparingData.

    procedure TGLBumpmapHDS.PreparingData(heightData: THeightData);
    var
    TmpHD: THeightData;
    libMat: TGLLibMaterial;
    bmp32: TGLBitmap32;
    MatName: string;
    begin
    if not assigned(FBumpmapLibrary) then
    exit;
    //--Generate Normal Map for tile--
    heightData.TextureCoordinatesMode := tcmLocal;
    heightData.TextureCoordinatesOffset := NullTexPoint;
    heightData.TextureCoordinatesScale := XYTexPoint;
    MatName := 'BumpHDS_x' + IntToStr(heightData.XLeft) + 'y' + IntToStr(heightData.YTop) + '.'; //name contains xy coordinates of the current tile
    Uno.Acquire;
    LibMat := FBumpmapLibrary.Materials.GetLibMaterialByName(MatName); //Check if Tile Texture already exists
    if LibMat = nil then
    begin
    if (FMaxTextures > 0) then
    begin
    if heightData.Thread = nil {//Dont trim the cache from a sub-thread;} then
    TrimTextureCache(FMaxTextures) //Trim unused textures from the material library
    end;
    //Generate new NormalMap texture for this tile
    libMat := FBumpmapLibrary.Materials.Add;
    libMat.Name := MatName;
    //Transfer tile texture coordinates to generated texture
    libMat.TextureScale.X := heightData.TextureCoordinatesScale.S;
    libMat.TextureScale.Y := heightData.TextureCoordinatesScale.T;
    libMat.TextureOffset.X := heightData.TextureCoordinatesOffset.S;
    libMat.TextureOffset.Y := heightData.TextureCoordinatesOffset.T;
    //------------------------------------------------------
    //--Set up new Normalmap texture for the current tile--
    libMat.Material.MaterialOptions := [moNoLighting];
    with libMat.Material.Texture do
    begin
    ImageClassName := TGLBlankImage.ClassName;
    Enabled := True;
    MinFilter := miNearestMipmapNearest;
    MagFilter := maLinear; //MagFilter:=maNearest;
    TextureMode := tmReplace;
    TextureWrap := twNone;
    TextureFormat := tfRGB16;
    //TextureFormat:=tfRGBA16;
    bmp32 := (Image as TGLBlankImage).GetBitmap32;
    TmpHD := HeightDataSource.GetData(heightData.XLeft - 1, heightData.YTop - 1, heightData.Size + 1, heightData.DataType);
    GenerateNormalMap(TmpHD, bmp32, FBumpScale);
    TmpHD.Release;
    end;
    //----------------------------------------------------
    end;
    //HD.MaterialName:=LibMat.Name;
    heightData.LibMaterial := LibMat; //attach texture to current tile
    if Assigned(FOnNewTilePrepared) then
    FOnNewTilePrepared(Self, heightData, libMat);
    Uno.Release;
    end;

     

    Last edit: lnebel 2015-01-08
  • Pavel Vassiliev

    Pavel Vassiliev - 2015-01-08

    Well, lnebel,
    I've changed GLBumpmapHDS in SVN with your version of PreparingData procedure, but in our demos there is no difference for old and new versions. So it might be well to give an example code how you getting the pictures.
    PW

     
    • lnebel

      lnebel - 2015-01-09

      Thanks

      The problem is solved in my projects for now. Hopefully it will not generate problems in other projects!

      Something broke in the terrain system in 2007. Since then I have been using an old copy of GLScene. Now I am finally up and running with the latest version again.

      I haven't had the time and energy to get into all the details of the TerrainRenderer and associated classes, but it really needs a brushup. I feel obligated to help doing that but I certainly don't have the time these days.

      Actually, the changed code in GLBumpmapHDS.PreparingData generates a subtle difference in the shaded terrain demo. The tile borders are less visible (at least different) with the new code. It seem that the shading is offset?

      Also, for both the old and new version the shading is not smooth across tile borders in the shaded terrain demo. For some reason I don't understand, that is not the case in my project?

      And finally, you are asking for a demo project. I would love to contribute with a demo project using a real terrain. It could provide a base for a brushup of the terrain system. However, that is not so easy to do at the moment...

      Lars

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.