Normal map shading for terrain tiles

Dear cesium developers,

I am currently looking for a way to add normal map shading
to heightmap-based terrain (backed by an elevation TMS), and I
have a few thoughts/questions I'd like to run by you:

1) Implementing normal map shading via terrain renderer

I would love an approach which can work directly on the TMS
elevation data, but implementing this in the cesium terrain renderer seems like a lot of work.

Do you have an idea for a quicker way to implement this (e.g. adding pre-generated normal maps as image layer, and using a custom fragment shader)?

2) HeightMap-based terrain

Is support for heightmap-based terrain being phased out? Just
asking because from what I remember cesium had more raster-based
terrain providers in older versions, I don't want to bet on
the wrong horse!

3) Implementing normal map shading on 3d tiles

Alternatively, I have thought about pre-processing the elevation data into 3d tiles, with accompanying normal maps. Does cesium currently support projectively texturing 3d tiles from imagery layers?

Thanks for reading this, and I'm grateful for your comments & suggestions!

Regards,

Manuel

Are you trying to do something like this?

I believe the way Globe Materials work is the shader uses the normals to color the pixels. There was also a recent PR to add the aspect as well so that it can be used to color:

As for heightmap-based terrain, it’s still supported, but we’ve been doing a lot more work on quantized mesh. There’s some more discussion on that in this thread: https://groups.google.com/d/msg/cesium-dev/KmEELn7LXAo/DSHrFLVtGgAJ

I think it’s more likely he is looking for a way to ADD normal to the terrain for better lighting that doesn’t need 1000’s of vertices in the mesh.

FWIW, I was looking at that too (low res mesh, high res lighting) but it doesn’t seem possible with Cesium as is.

Hi Omar,
Hi Benjamin,

thanks for your input!

It's good to hear heightmaps are not deprecated.

As Benjamin correctly noted, I want to apply normal maps in order to add
detailed normals to the terrain geometry (independent of mesh tesselation).

Basically, terrain normal maps can be parametrized and sampled the same
way as the usual ImageyLayers (aka "daytextures" in
GlobeSurfaceShaderSet), so fortunately a lot of the required setup is
already present.

AFAICT, the steps currently missing for working normal maps:

- designate an ImageryLayer as normal map layer (e.g. via flag)
- setup samplers + parameters (scaling, offset etc.) for normal map:
  analoguous to dayTextureSetup in GlobeSurfaceTile.js; normal map must
  be bound for each pass when using multi-pass rendering

- Adapt fragment shader in GlobeSurfaceShaderSet.js:
  - decoding of normal into appropriate coordinate frame (possibly
    with support from VS, e.g. tangent space vectors)
  - diffuse shading in the fragment shader
  - add define + conditional code sections to FS, e.g. "#define
    ENABLE_NORMAL_MAPS"

Looks doable, although it might still be out of scope for my
current project.

cheers,

Manuel

Ah, I see what you mean. That sounds like it would be a pretty awesome feature! We’d definitely appreciate a contribution to that effect. If you’ve got something started in a fork I’d be happy to take a look, or another way to get feedback would be to open a work-in-progress PR.