How to apply bloom effect to a single object?

192 views
Skip to first unread message

Jalien

unread,
Jul 4, 2019, 5:02:08 AM7/4/19
to cesium-dev
1. A concise explanation of the problem you're experiencing.

I want to apply a bloom effect to a single object. I looked at the post-processing of cesium. It seems that the bloom effect can only be applied globally.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I want to draw some geometry, the surface of the geometry is a transparent material, the outline of the geometry is applied to the bloom effect, and the reason for using the bloom effect is to highlight the outline and look beautiful.

4. The Cesium version you're using, your operating system and browser.

cesium1.5.9,windows 10 x64,chrome 75.0.3770.100.

Omar Shehata

unread,
Jul 8, 2019, 10:24:12 AM7/8/19
to cesium-dev
Hey Jalien,

Thanks for bringing this up! Looks like the bloom shader just doesn't check for the selected feature property. I opened a feature request for it here with some suggestions on how this can be accomplished:


Do note that feature selection currently only works for models/primitives, not entities.

Jalien

unread,
Jul 9, 2019, 6:45:35 AM7/9/19
to cesium-dev

I changed the BloomComposite.glsl code as follows,then rebuild cesium, but the problem persists.
uniform sampler2D colorTexture;
uniform sampler2D bloomTexture
;
uniform
bool  glowOnly;

varying vec2 v_textureCoordinates
;

void main(void)
{
    vec4 color
= texture2D(colorTexture, v_textureCoordinates);
   
#ifdef CZM_SELECTED_FEATURE
   
if (czm_selected()) {
        gl_FragColor
= color;
       
return;
   
}
#endif

    vec4 bloom
= texture2D(bloomTexture, v_textureCoordinates);
    gl_FragColor
= glowOnly ? bloom : bloom + color;
}



在 2019年7月8日星期一 UTC+8下午10:24:12,Omar Shehata写道:

Omar Shehata

unread,
Jul 9, 2019, 2:11:47 PM7/9/19
to cesium-dev
Did you verify that the CZM_SELECTED_FEATURE definition was getting added to the shader? There might be a step I missed for that in the PostProcessStage class to add that definition when constructing the shader.

Jalien

unread,
Jul 9, 2019, 9:37:59 PM7/9/19
to cesium-dev
Hi,Omar,Thank you for your reply.

The CZM_SELECTED_FEATURE is defined here, I debug the code, after running this line of code, the shader code is as follows:
#define CZM_SELECTED_FEATURE 
uniform sampler2D czm_idTexture; 
uniform sampler2D czm_selectedIdTexture; 
uniform float czm_selectedIdTextureStep; 
varying vec2 v_textureCoordinates; 
bool czm_selected(vec2 offset) 
    bool selected = false;
    vec4 id = texture2D(czm_idTexture, v_textureCoordinates + offset); 
    for (int i = 0; i < 1; ++i) 
    { 
        vec4 selectedId = texture2D(czm_selectedIdTexture, vec2(float(i) * czm_selectedIdTextureStep, 0.5)); 
        if (all(equal(id, selectedId))) 
        { 
            return true; 
        } 
    } 
    return false; 

bool czm_selected() 
    return czm_selected(vec2(0.0)); 

uniform sampler2D colorTexture;
uniform sampler2D bloomTexture;
uniform bool  glowOnly;



void main(void)
{
    vec4 color = texture2D(colorTexture, v_textureCoordinates);
    
#ifdef CZM_SELECTED_FEATURE
    if (czm_selected()) {
        gl_FragColor = color;
        return;
    }
#endif

    vec4 bloom = texture2D(bloomTexture, v_textureCoordinates);
    gl_FragColor = glowOnly ? bloom : bloom + color;
}



在 2019年7月10日星期三 UTC+8上午2:11:47,Omar Shehata写道:
Reply all
Reply to author
Forward
0 new messages