Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTF to Raster #6

Open
jgoffeney opened this issue Apr 29, 2022 · 17 comments
Open

GLTF to Raster #6

jgoffeney opened this issue Apr 29, 2022 · 17 comments

Comments

@jgoffeney
Copy link
Owner

Currently able to load the GLTF / GLB and render using a glOrtho based on the model bounds and essentially a passthrough for the shaders using the original POSITION vertex data.

Currently the test GLB file was generated as Geotiff->Unreal->mesh->FBX->Blender->GLB.

Issues:

  • Test GLB
    • The mesh was generated by script within Unreal from Lat/Lon raster data and converted to meters which removes the base grid. It is better to use projected data with equal 1 cell spacing.
    • When exporting from blender it creates Camera and Light nodes in the GLB which have their own transforms. It is better to just ignore the node transforms in favor of just working with the data. It makes the shaders very simple and setting up glOrtho easy by just using the GLTF POSITION vertex data.

To Dos:

  • Create a test mesh to try to get as close to a 1 to 1 raster input and output in the pipeline.
  • Try with terracotta data
    • It is in a format that already follows the curvature of the earth.
@jgoffeney
Copy link
Owner Author

Something else to consider is the glViewport needs to have the resolution of the target raster. However the model bounds based on the input vertices will likely not have the same mapping.

For my test the source is 2000 x 2000. The model vertices need to be transformed to map to these bounds to generate the same output for the ground plane. However the elevation needs to remain the same.

@jgoffeney
Copy link
Owner Author

Updated the argument parser to remove some internally set variables and added geospatial params. Created vertexRasterShaderSource to handle the vertex transformations.

tx = (vx - vertMinX) /(vertMaxX - vertMinX) * winX

@jgoffeney
Copy link
Owner Author

The following orthographic projection sets up the correct rendering region.

glOrtho(0, argParams.targetWidth, 0, -argParams.targetHeight, -maxY, -minY);

@jgoffeney
Copy link
Owner Author

jgoffeney commented May 5, 2022

What currently works:

  • Added GLM for linear algebra tasks.
  • Added command line rotation to position model to face camera.
  • Setup orthographic projection to correctly handle extent of model with rotation and translation.

To Do:

  • Scale the model. Currently the model is using "geospatial coordinates" but needs to be expanded to have each point have 1 pixel spacing.
    • For a 2000 x 2000 image need the model and ortho to use ranges of -1000 to 1000 for spatial dimensions.
  • May need to generate a better test model.

@jgoffeney
Copy link
Owner Author

Current command

.\glb2raster.exe -mode framebuffer -targetdims 2000 2000 -geoOrigin -78.0085059999999970 34.0003519999999995 -pixelDims 4.000000000001892938e-06 -4.000000000001892938e-06 -rotate  90 1 0 0 ..\..\..\data\meshgrid_0_0.glb meshgrid.asc

@jgoffeney
Copy link
Owner Author

The 3d tile JSON file has the LLA geospatial bounds so we can use that to create the initial ROI and then determine spacing. Think like WCS coverage call. Then ECEF to LLA

@jgoffeney
Copy link
Owner Author

The root JSON bounds for the 0/0/0/0/json file. Note it is in the format minX, minY, maxX, maxY, minZ, maxZ with the X and Y in radians.

"boundingVolume":{
         "region":[
            -0.7853981633974483,
            -0.5406359802559503,
            0.7853981633974483,
            0.785398163381105,
            -10170.587093897164,
            5874.600580642931
         ]
      }

Degrees:

  • minX = -45
  • minY = -30.97616
  • maxX = 45
  • maxY = 45

@jgoffeney
Copy link
Owner Author

jgoffeney commented May 11, 2022

Current test for framebuffer output with shader files.

 .\glb2raster.exe -mode framebuffer -vs ..\..\..\shaders\SimpleVertexShader.txt  -fs ..\..\..\shaders\SimpleFramebufferFragmentShader.txt -targetdims 2000 2000 -geoOrigin -78.00850200000 34.00035600000 -pixelDims 4.000000000001892938e-06 -4.000000000001892938e-06 -rotate  90 1 0 0 -outputScale 1.0 0.01 1.0 ..\..\..\data\meshgrid_0_0.glb meshgrid_doub_scale_refactor_shadefile.asc

Windows test with shader files

.\glb2raster.exe -mode window -vs ..\..\..\shaders\SimpleVertexShader.txt  -fs ..\..\..\shaders\SimpleWindowFragmentShader.txt -targetdims 2000 2000 -rotate  90 1 0 0 ..\..\..\data\meshgrid_0_0.glb

@jgoffeney
Copy link
Owner Author

The JSON file is loaded during argument parsing and at the end updates the values. The mode and the presence JSON content indicates the code path.

The vertex program is the ECEF2LLA conversion while the fragment program just writes the altitude to the red channel.

@jgoffeney
Copy link
Owner Author

Converted shaders for GL 3.3. Need to fix ECEF shaders as outputs are currently empty.

@jgoffeney
Copy link
Owner Author

Current Save:
SavePoint

@jgoffeney
Copy link
Owner Author

Look at cesium-native Cesium3DTilesSelection::GltfContent line 420.

@jgoffeney
Copy link
Owner Author

The solution for the cartographic coordinates is to first apply the GLTF node transform and then apply the following:

1 0 0 0
0 0 -1 0
0 1 0 0
0 0 0 1

(https://github.com/CesiumGS/3d-tiles/blob/main/specification/README.md#transforms)[See implementation note).

Still issues with Z coord.

@jgoffeney
Copy link
Owner Author

Currently Excel and shader results agree for transforming the GLTF ECEF to correct ECEF. Excel and web ECEF->LLA calculator agree for final result but I need to check why all points are clipped out when using transformed ECEF -> LLA in shader.

@jgoffeney
Copy link
Owner Author

The shader appears to be producing the correct lat/lon values and altitude is at least looks relatively correct.
GLTFFirstSuccess

@jgoffeney
Copy link
Owner Author

Removed the JSON requirement for tile 3d since parsing the files gets a complicated for some child nodes. Instead added a -cartoBounds parameter as (minX,maxX,minY,maxY,minZ,maxZ).

@jgoffeney
Copy link
Owner Author

Working command

.\glb2raster.exe -mode framebuffer -vs ..\..\..\shaders\ECEF2LLAVertexShader.txt  -fs ..\..\..\shaders\ECEF2LLAFramebufferFragmentShader.txt -targetdims 2000 2000 -cartoBounds 37.29720442 39.98123466 32.72223247 36.13867295 -402.63580276910218 1426.4234313657508 ..\..\..\data\latest_dsm_data_0_713.3tz_0_5_29_30.glb latest_dsm_index_0_713.3tz_0_5_29_30EUpdateAscTest.asc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant