Model Shading/Lighting

We have successfully converted OBJ models to COLLADA and then GLTF. The models and textures are appearing correctly. However, depending on the angle from the camera to the model there is shading being applied that makes parts of the model very dark.

In other software we have been able to modify the luminosity to override this shading effect and still see the texture, but we have not found any way to eliminate the shading in Cesium.

We have turned off the lighting on the globe and made adjustments to every material parameter (ambient, diffuse, specular, emissions, shininess) without the desired result.

Is there a way to eliminate this shading effect (while retaining the image texture)?

There’s not a official way to do this yet. Cesium just uses the default shader generated from the COLLADA common profile. To workaround this, you can tweak the fragment shader to have more ambient light (and less diffuse/specular if you want) so it appears bright regardless of the viewing angle. This use to be very easy, but now the online converter embeds and base64 encodes the shader (for example, see here) so you could either (1) convert offline and not embed resources so it is easy to patch the shader, or (2) patch the shader at runtime after it is loaded (see here).

Patrick

Hi Patrick,

Thanks for the response. We think we'd like to patch the shader at runtime, but would like to be able to do this without modifying the Cesium source code if possible. Could this be done by modifying the glTF object instance? Any pointers or examples you could provide would be appreciated.

Load the .gltf file into a JavaScript object with loadText and JSON.parse. Traverse it to find the shader source for each fragment shader. Get the base64-decoded source using loadText (like this). Patch the shader and base64 encode it. Create a data URI and assign it back to the shader source in the glTF JavaScript object. Create the glTF model using “new Model” like this.

Patrick

Thanks again for your help.

Sorry for the late response, but for anyone interested in our solution here's what we did.

1. We opened up our model files after converting them to gltf

2. Searched for the "shaders" section

3. Copied the base64 text under "uri" of the "(modelid)0FS" shader

4. Dencoded the text using https://www.base64decode.org/ and found this line : diffuse.xyz *= max(dot(normal,vec3(0.,0.,1.)), 0.);

5. We replaced that line with this
diffuse.xyz *= .97;

6. Reencoded the entire text, and saved it back into the model using a text editor.

We figured since this was a hack, we might as well just do a find and replace of the encoded text with the modified encoded text on every one of our models.

This way we don't have to do anything extra at runtime.