USNavalResearchLaboratory / simdissdk

SIMDIS SDK
Other
114 stars 39 forks source link

Override 3D Model Color #104

Closed faculaganymede closed 4 months ago

faculaganymede commented 4 months ago

I'm using the functions mutable_commonprefs()->set_useoverridecolor(true) and mutable_commonprefs()->set_overridecolor() from simData::PlatformPrefs to change the color of a 3D model displayed in the scene. The results appear to show that these functions blend the new color with the original color of the 3D model rather than overriding. Am I missing a setting?

Below is an example with override colors applied to the SIMDIS EXAMPLE_AIRPLANE_ICON model. First picture shows that original model color, second picture shows Yellow as the applied override color, and third picture shows Dark Blue as the applied override color. Notice the Yellow color barely had any effect.

image

emminizer commented 4 months ago

Take a look at OverrideColorCombineMode, set with PlatformPrefs::set_overridecolorcombinemode(). There are 3 options:

/// Override color combination mode
enum OverrideColorCombineMode {
  /// Multiply the override color against incoming color; good for shaded items and 2D images
  MULTIPLY_COLOR = 0;
  /// Replace the incoming color with the override color; good for flat items
  REPLACE_COLOR = 1;
  /// Apply color by copying the previous color intensity and replacing with this one, retaining shading better than REPLACE_COLOR
  INTENSITY_GRADIENT = 2;
};

The INTENSITY_GRADIENT is new (in the last month) but provides results that are likely what you're looking for. We currently default to MULTIPLY_COLOR. You can try REPLACE_COLOR but it will likely be not as useful for you.

emminizer commented 4 months ago

You can also refer to the shader at https://github.com/USNavalResearchLaboratory/simdissdk/blob/main/SDK/simVis/OverrideColor.frag.glsl and experiment with different techniques of your own if you don't like the ones that ship in SIMDIS SDK.

faculaganymede commented 4 months ago

Thank you emminizer, appreciated your help as always. I'm using an older version of the SDK 1.17 that doesn't have this function yet. Let me try to upgrade to the latest SDK.

emminizer commented 4 months ago

If updating is not feasible, you can implement the shader on your own with some code on your side, or modify your shader code locally such that COLOR_MULTIPLY path changes the fragment coloring. If you deploy shader files with your application, you can also make this change without making any actual code changes and just editing the GLSL file that gets loaded at runtime.

faculaganymede commented 4 months ago

Thank you so much for the suggestion!!