Updated from OpenSceneGraph-Data/shaders/text_sdf.frag to add support for SHADOW
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"#pragma import_defines( BACKDROP_COLOR, OUTLINE, SIGNED_DISTNACE_FIELD, TEXTURE_DIMENSION, GLYPH_DIMENSION)\n"
|
||||
"#pragma import_defines( BACKDROP_COLOR, SHADOW, OUTLINE, SIGNED_DISTNACE_FIELD, TEXTURE_DIMENSION, GLYPH_DIMENSION)\n"
|
||||
"\n"
|
||||
"#ifdef GL_ES\n"
|
||||
" #extension GL_OES_standard_derivatives : enable\n"
|
||||
@@ -99,11 +99,11 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"vec4 distanceFieldColor()\n"
|
||||
"vec4 textColor(vec2 src_texCoord)\n"
|
||||
"{\n"
|
||||
" float sample_distance_scale = 0.75;\n"
|
||||
" vec2 dx = dFdx(texCoord)*sample_distance_scale;\n"
|
||||
" vec2 dy = dFdy(texCoord)*sample_distance_scale;\n"
|
||||
" vec2 dx = dFdx(src_texCoord)*sample_distance_scale;\n"
|
||||
" vec2 dy = dFdy(src_texCoord)*sample_distance_scale;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" float distance_across_pixel = length(dx+dy)*(TEXTURE_DIMENSION/GLYPH_DIMENSION);\n"
|
||||
@@ -130,7 +130,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" float blend_half_width = blend_width*0.5;\n"
|
||||
"\n"
|
||||
" // check whether fragment is wholly within or outwith glyph body+outline\n"
|
||||
" float cd = distanceFromEdge(texCoord); // central distance (distance from center to edge)\n"
|
||||
" float cd = distanceFromEdge(src_texCoord); // central distance (distance from center to edge)\n"
|
||||
" if (cd-blend_half_width>distance_across_pixel) return vertexColor; // pixel fully within glyph body\n"
|
||||
"\n"
|
||||
" #ifdef OUTLINE\n"
|
||||
@@ -142,7 +142,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" // use multi-sampling to provide high quality antialised fragments\n"
|
||||
" vec2 origin = texCoord - dx*0.5 - dy*0.5;\n"
|
||||
" vec2 origin = src_texCoord - dx*0.5 - dy*0.5;\n"
|
||||
" for(;numSamplesY>0; --numSamplesY)\n"
|
||||
" {\n"
|
||||
" vec2 pos = origin;\n"
|
||||
@@ -164,16 +164,16 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
"vec4 textureColor()\n"
|
||||
"vec4 textColor(vec2 src_texCoord)\n"
|
||||
"{\n"
|
||||
" float alpha = TEXTURE(glyphTexture, texCoord).a;\n"
|
||||
"\n"
|
||||
"#ifdef OUTLINE\n"
|
||||
"\n"
|
||||
" float alpha = TEXTURE(glyphTexture, src_texCoord).a;\n"
|
||||
" float delta_tc = 1.6*OUTLINE*GLYPH_DIMENSION/TEXTURE_DIMENSION;\n"
|
||||
"\n"
|
||||
" float outline_alpha = alpha;\n"
|
||||
" vec2 origin = texCoord-vec2(delta_tc*0.5, delta_tc*0.5);\n"
|
||||
" vec2 origin = src_texCoord-vec2(delta_tc*0.5, delta_tc*0.5);\n"
|
||||
"\n"
|
||||
" float numSamples = 3.0;\n"
|
||||
" delta_tc = delta_tc/(numSamples-1);\n"
|
||||
@@ -191,7 +191,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" #ifdef osg_TextureQueryLOD\n"
|
||||
" float mipmapLevel = osg_TextureQueryLOD(glyphTexture, texCoord).x;\n"
|
||||
" float mipmapLevel = osg_TextureQueryLOD(glyphTexture, src_texCoord).x;\n"
|
||||
" if (mipmapLevel<1.0)\n"
|
||||
" {\n"
|
||||
" outline_alpha = mix(1.0-background_alpha, outline_alpha, mipmapLevel/1.0);\n"
|
||||
@@ -209,8 +209,11 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" return color;\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" float alpha = TEXTURE(glyphTexture, src_texCoord).a;\n"
|
||||
" if (alpha==0.0) vec4(0.0, 0.0, 0.0, 0.0);\n"
|
||||
" return vec4(vertexColor.rgb, vertexColor.a * alpha);\n"
|
||||
"\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -225,10 +228,16 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"#ifdef SIGNED_DISTNACE_FIELD\n"
|
||||
" vec4 color = distanceFieldColor();\n"
|
||||
"#ifdef SHADOW\n"
|
||||
" float scale = -1.0*GLYPH_DIMENSION/TEXTURE_DIMENSION;\n"
|
||||
" vec2 delta_tc = SHADOW*scale;\n"
|
||||
" vec4 shadow_color = textColor(texCoord+delta_tc);\n"
|
||||
" shadow_color.rgb = BACKDROP_COLOR.rgb;\n"
|
||||
"\n"
|
||||
" vec4 glyph_color = textColor(texCoord);\n"
|
||||
" vec4 color = mix(shadow_color, glyph_color, glyph_color.a);\n"
|
||||
"#else\n"
|
||||
" vec4 color = textureColor();\n"
|
||||
" vec4 color = textColor(texCoord);\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" if (color.a==0.0) discard;\n"
|
||||
|
||||
Reference in New Issue
Block a user