您的位置:首页 > 游戏 > 游戏 > Cesium billboard 自定义shader实现描边效果

Cesium billboard 自定义shader实现描边效果

2024/11/17 5:29:42 来源:https://blog.csdn.net/qq_21476953/article/details/142356222  浏览:    关键词:Cesium billboard 自定义shader实现描边效果

Cesium billboard 自定义shader实现描边效果

在这里插入图片描述

      uniform sampler2D u_atlas;uniform vec2 dimensions;in vec2 v_textureCoordinates;in vec4 v_pickColor;in vec4 v_color;in float v_splitDirection;void main(){if (v_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;if (v_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;float outlineWidth = 2.0;vec2 uv = v_textureCoordinates;vec2 uv_up = vec2(uv.x, uv.y + 1./dimensions.y * outlineWidth);vec2 uv_down = vec2(uv.x, uv.y - 1./dimensions.y * outlineWidth);vec2 uv_left = vec2(uv.x + 1./dimensions.x * outlineWidth, uv.y);vec2 uv_right = vec2(uv.x - 1./dimensions.x * outlineWidth, uv.y);vec4 color_up = texture(u_atlas, uv_up);vec4 color_down = texture(u_atlas, uv_down);vec4 color_left = texture(u_atlas, uv_left);vec4 color_right = texture(u_atlas, uv_right);vec4 outlineColor = color_left + color_right + color_up + color_down;// outlineColor = outlineColor / 4.0;outlineColor.rgb = vec3(1., 0., 0.);vec4 rayColor = texture(u_atlas, uv);vec4 color = mix(outlineColor,rayColor, rayColor.a);color = czm_gammaCorrect(color);// Fully transparent parts of the billboard are not pickable.#if !defined(OPAQUE) && !defined(TRANSLUCENT)if (color.a < 0.005)   // matches 0/255 and 1/255{discard;}#else// The billboard is rendered twice. The opaque pass discards translucent fragments// and the translucent pass discards opaque fragments.#ifdef OPAQUEif (color.a < 0.995)   // matches < 254/255{discard;}#elseif (color.a >= 0.995)  // matches 254/255 and 255/255{discard;}#endif#endif#ifdef VECTOR_TILEcolor *= u_highlightColor;#endifout_FragColor = color;#ifdef LOG_DEPTHczm_writeLogDepth();#endif

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com