Updated shaders from OpenSceneGraph-Data.
This commit is contained in:
parent
2f043345c9
commit
16cd192562
@ -21,18 +21,26 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" #endif\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"$OSG_PRECISION_FLOAT\n"
|
||||
"\n"
|
||||
"#if __VERSION__>=130\n"
|
||||
" #define TEXTURE texture\n"
|
||||
" #define TEXTURELOD textureLod\n"
|
||||
" out vec4 osg_FragColor;\n"
|
||||
"#else\n"
|
||||
" #define TEXTURE texture2D\n"
|
||||
" #define TEXTURELOD texture2DLod\n"
|
||||
" #define osg_FragColor gl_FragColor\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if __VERSION__>=130\n"
|
||||
" #define TEXTURELOD textureLod\n"
|
||||
"#else\n"
|
||||
" #ifdef GL_ES\n"
|
||||
" #extension GL_EXT_shader_texture_lod : enable\n"
|
||||
" #ifdef GL_EXT_shader_texture_lod\n"
|
||||
" #define TEXTURELOD texture2DLodEXT\n"
|
||||
" #else\n"
|
||||
" #define TEXTURELOD texture2DLod\n"
|
||||
" #endif\n"
|
||||
" #else\n"
|
||||
" #define TEXTURELOD texture2DLod\n"
|
||||
" #endif\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if !defined(GL_ES) && __VERSION__>=130\n"
|
||||
" #define ALPHA r\n"
|
||||
@ -42,6 +50,13 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" #define SDF r\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"$OSG_PRECISION_FLOAT\n"
|
||||
"\n"
|
||||
"#if __VERSION__>=130\n"
|
||||
" out vec4 osg_FragColor;\n"
|
||||
"#else\n"
|
||||
" #define osg_FragColor gl_FragColor\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"uniform sampler2D glyphTexture;\n"
|
||||
"\n"
|
||||
@ -70,45 +85,49 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" return (center_alpha-0.5)*distance_scale;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"vec4 distanceFieldColorSample(float edge_distance, float blend_width, float blend_half_width)\n"
|
||||
"{\n"
|
||||
"#ifdef OUTLINE\n"
|
||||
"vec2 colorCoeff(float edge_distance, float blend_width, float blend_half_width)\n"
|
||||
"{\n"
|
||||
" float outline_width = OUTLINE*0.5;\n"
|
||||
" if (edge_distance>blend_half_width)\n"
|
||||
" {\n"
|
||||
" return vertexColor;\n"
|
||||
" return vec2(1.0, 0.0);\n"
|
||||
" }\n"
|
||||
" else if (edge_distance>-blend_half_width)\n"
|
||||
" {\n"
|
||||
" return mix(vertexColor, vec4(BACKDROP_COLOR.rgb, BACKDROP_COLOR.a*vertexColor.a), smoothstep(0.0, 1.0, (blend_half_width-edge_distance)/(blend_width)));\n"
|
||||
" float f = smoothstep(0.0, 1.0, (blend_half_width-edge_distance)/(blend_width));\n"
|
||||
" return vec2(1.0 - f, f);\n"
|
||||
" }\n"
|
||||
" else if (edge_distance>(blend_half_width-outline_width))\n"
|
||||
" {\n"
|
||||
" return vec4(BACKDROP_COLOR.rgb, BACKDROP_COLOR.a*vertexColor.a);\n"
|
||||
" return vec2(0.0, 1.0);\n"
|
||||
" }\n"
|
||||
" else if (edge_distance>-(outline_width+blend_half_width))\n"
|
||||
" {\n"
|
||||
" return vec4(BACKDROP_COLOR.rgb, vertexColor.a * ((blend_half_width+outline_width+edge_distance)/blend_width));\n"
|
||||
" return vec2(0.0, smoothstep(0.0, 1.0, (blend_half_width+outline_width+edge_distance)/blend_width));\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" return vec4(0.0, 0.0, 0.0, 0.0);\n"
|
||||
" return vec2(0.0, 0.0);\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"#else\n"
|
||||
"float colorCoeff(float edge_distance, float blend_width, float blend_half_width)\n"
|
||||
"{\n"
|
||||
" if (edge_distance>blend_half_width)\n"
|
||||
" {\n"
|
||||
" return vertexColor;\n"
|
||||
" return 1.0;\n"
|
||||
" }\n"
|
||||
" else if (edge_distance>-blend_half_width)\n"
|
||||
" {\n"
|
||||
" return vec4(vertexColor.rgb, vertexColor.a * smoothstep(1.0, 0.0, (blend_half_width-edge_distance)/(blend_width)));\n"
|
||||
" return smoothstep(1.0, 0.0, (blend_half_width-edge_distance)/(blend_width));\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" return vec4(0.0, 0.0, 0.0, 0.0);\n"
|
||||
" return 0.0;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"vec4 textColor(vec2 src_texCoord)\n"
|
||||
"{\n"
|
||||
@ -134,9 +153,6 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" vec2 delta_ty = dy/float(numSamplesY-1);\n"
|
||||
"\n"
|
||||
" float numSamples = float(numSamplesX)*float(numSamplesY);\n"
|
||||
" float scale = 1.0/numSamples;\n"
|
||||
" vec4 total_color = vec4(0.0,0.0,0.0,0.0);\n"
|
||||
"\n"
|
||||
" float blend_width = 1.5*distance_across_pixel/numSamples;\n"
|
||||
" float blend_half_width = blend_width*0.5;\n"
|
||||
"\n"
|
||||
@ -147,11 +163,12 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" #ifdef OUTLINE\n"
|
||||
" float outline_width = OUTLINE*0.5;\n"
|
||||
" if ((-cd-outline_width-blend_half_width)>distance_across_pixel) return vec4(0.0, 0.0, 0.0, 0.0); // pixel fully outside outline+glyph body\n"
|
||||
" vec2 color_coeff = vec2(0.0, 0.0);\n"
|
||||
" #else\n"
|
||||
" if (-cd-blend_half_width>distance_across_pixel) return vec4(0.0, 0.0, 0.0, 0.0); // pixel fully outside glyph body\n"
|
||||
" float color_coeff = 0.0;\n"
|
||||
" #endif\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" // use multi-sampling to provide high quality antialised fragments\n"
|
||||
" vec2 origin = src_texCoord - dx*0.5 - dy*0.5;\n"
|
||||
" for(;numSamplesY>0; --numSamplesY)\n"
|
||||
@ -160,17 +177,28 @@ char osgText_Text_frag[] = "$OSG_GLSL_VERSION\n"
|
||||
" int numX = numSamplesX;\n"
|
||||
" for(;numX>0; --numX)\n"
|
||||
" {\n"
|
||||
" vec4 c = distanceFieldColorSample(distanceFromEdge(pos), blend_width, blend_half_width);\n"
|
||||
" total_color = total_color + c * c.a;\n"
|
||||
" #ifdef OUTLINE\n"
|
||||
" color_coeff += colorCoeff(distanceFromEdge(pos), blend_width, blend_half_width);\n"
|
||||
" #else\n"
|
||||
" color_coeff += colorCoeff(distanceFromEdge(pos), blend_width, blend_half_width);\n"
|
||||
" #endif\n"
|
||||
" pos += delta_tx;\n"
|
||||
" }\n"
|
||||
" origin += delta_ty;\n"
|
||||
" }\n"
|
||||
" color_coeff /= numSamples;\n"
|
||||
" \n"
|
||||
" #ifdef OUTLINE\n"
|
||||
" float vertex_alpha = vertexColor.a * color_coeff.x;\n"
|
||||
" float outline_alpha = BACKDROP_COLOR.a * color_coeff.y;\n"
|
||||
" float total_alpha = vertex_alpha + outline_alpha;\n"
|
||||
"\n"
|
||||
" total_color.rgb /= total_color.a;\n"
|
||||
" total_color.a *= scale;\n"
|
||||
" if (total_alpha <= 0.0) return vec4(0.0, 0.0, 0.0, 0.0);\n"
|
||||
"\n"
|
||||
" return total_color;\n"
|
||||
" return vec4(vertexColor.rgb * (vertex_alpha / total_alpha) + BACKDROP_COLOR.rgb * (outline_alpha / total_alpha), total_alpha);\n"
|
||||
" #else\n"
|
||||
" return vec4(vertexColor.rgb, vertexColor.a * color_coeff);\n"
|
||||
" #endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
|
Loading…
Reference in New Issue
Block a user