Updated shader from OpenSceneGraph-Data/shaders to add fade out for SDF and non SDF pathways
This commit is contained in:
parent
ca5a8a81a2
commit
6ec9f0a3d3
@ -2,21 +2,15 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"#pragma import_defines( BACKDROP_COLOR, OUTLINE, SIGNED_DISTNACE_FIELD )\n"
|
||||
"\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD\n"
|
||||
"\n"
|
||||
" #if !defined(GL_ES)\n"
|
||||
" #if __VERSION__>=400\n"
|
||||
" #define osg_TextureQueryLOD textureQueryLod\n"
|
||||
" #define SIGNED_DISTNACE_FIELD_SUPPORTED\n"
|
||||
" #else\n"
|
||||
" #extension GL_ARB_texture_query_lod : enable\n"
|
||||
" #ifdef GL_ARB_texture_query_lod\n"
|
||||
" #define osg_TextureQueryLOD textureQueryLOD\n"
|
||||
" #define SIGNED_DISTNACE_FIELD_SUPPORTED\n"
|
||||
" #endif\n"
|
||||
"#if !defined(GL_ES)\n"
|
||||
" #if __VERSION__>=400\n"
|
||||
" #define osg_TextureQueryLOD textureQueryLod\n"
|
||||
" #else\n"
|
||||
" #extension GL_ARB_texture_query_lod : enable\n"
|
||||
" #ifdef GL_ARB_texture_query_lod\n"
|
||||
" #define osg_TextureQueryLOD textureQueryLOD\n"
|
||||
" #endif\n"
|
||||
" #endif\n"
|
||||
"\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"$OSG_PRECISION_FLOAT\n"
|
||||
@ -44,16 +38,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" // glyph.rgba = (signed_distance, thin_outline, thick_outline, glyph_alpha)\n"
|
||||
" vec4 glyph = TEXTURE(glyphTexture, texCoord);\n"
|
||||
"\n"
|
||||
" #ifdef SIGNED_DISTNACE_FIELD_SUPPORTED\n"
|
||||
" float blend_ratio = OUTLINE*20.0; // assume inner boundary starts at OUTLINE==0.05\n"
|
||||
"\n"
|
||||
" float outline_alpha = 0.0;\n"
|
||||
" if (blend_ratio>2.0) outline_alpha = glyph.b;\n"
|
||||
" else if (blend_ratio>1.0) outline_alpha = mix(glyph.g, glyph.b, blend_ratio-1.0);\n"
|
||||
" else outline_alpha = glyph.g*blend_ratio;\n"
|
||||
" #else\n"
|
||||
" float outline_alpha = (OUTLINE<=0.075) ? glyph.g : glyph.b;\n"
|
||||
" #endif\n"
|
||||
" float outline_alpha = (OUTLINE<=0.1) ? glyph.g : glyph.b;\n"
|
||||
"\n"
|
||||
" float alpha = glyph.a+outline_alpha;\n"
|
||||
" if (alpha>1.0) alpha = 1.0;\n"
|
||||
@ -67,17 +52,18 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" #endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD_SUPPORTED\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD\n"
|
||||
"vec4 distanceFieldColor()\n"
|
||||
"{\n"
|
||||
" float center_alpha = TEXTURELOD(glyphTexture, texCoord, 0.0).r;\n"
|
||||
" //float center_alpha = TEXTURE(glyphTexture, texCoord).r;\n"
|
||||
"\n"
|
||||
" float blend_width = 0.005;\n"
|
||||
" float distance_scale = 0.25;\n"
|
||||
" float edge_distance = (center_alpha-0.5)*distance_scale;\n"
|
||||
"\n"
|
||||
" #ifdef OUTLINE\n"
|
||||
" float outline_width = OUTLINE*0.5;;\n"
|
||||
" float outline_width = OUTLINE*0.5;\n"
|
||||
" if (edge_distance>blend_width*0.5)\n"
|
||||
" {\n"
|
||||
" return vertexColor;\n"
|
||||
@ -118,10 +104,18 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" float near_fade_away = 2.0;\n"
|
||||
" float far_fade_away = near_fade_away+5.0;\n"
|
||||
"\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD_SUPPORTED\n"
|
||||
"\n"
|
||||
"#ifdef osg_TextureQueryLOD\n"
|
||||
" float mml = osg_TextureQueryLOD(glyphTexture, texCoord).x;\n"
|
||||
" if (mml>far_fade_away) discard;\n"
|
||||
"#else\n"
|
||||
" float mml = 0.0;\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD\n"
|
||||
"\n"
|
||||
" float near_transition = 0.0;\n"
|
||||
" float far_transition = near_transition+1.0;\n"
|
||||
@ -137,6 +131,8 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" if (mml>near_fade_away) color.a *= (far_fade_away-mml)/(far_fade_away-near_fade_away);\n"
|
||||
"\n"
|
||||
" if (color.a==0.0) discard;\n"
|
||||
"\n"
|
||||
" osg_FragColor = color;\n"
|
||||
|
Loading…
Reference in New Issue
Block a user