1
0
Fork 0

Add shaders for osgText

This commit is contained in:
Fernando García Liñán 2021-05-14 22:45:36 +02:00
parent 55b0cf802c
commit 49fa42faac
3 changed files with 83 additions and 0 deletions

23
Effects/text-default.eff Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/text-default</name>
<technique n="10">
<pass>
<lighting>true</lighting>
<blend>
<active>true</active>
</blend>
<rendering-hint>transparent</rendering-hint>
<program>
<vertex-shader>Shaders/text.vert</vertex-shader>
<fragment-shader>Shaders/text.frag</fragment-shader>
<fragment-shader>Shaders/include_fog.frag</fragment-shader>
</program>
<uniform>
<name>glyphTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
</pass>
</technique>
</PropertyList>

44
Shaders/text.frag Normal file
View file

@ -0,0 +1,44 @@
#version 120
uniform sampler2D glyphTexture;
varying vec4 diffuse_term;
varying vec3 normal;
varying vec4 ecPosition;
////fog "include" /////
vec3 fog_Func(vec3 color, int type);
//////////////////////
void main()
{
float alpha = texture2D(glyphTexture, gl_TexCoord[0].st).a;
if (alpha == 0.0) discard;
float NdotL, NdotHV, fogFactor;
vec4 color = gl_Color;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 fragColor;
vec4 specular = vec4(0.0);
NdotL = dot(normal, lightDir);
if (NdotL > 0.0) {
color += diffuse_term * NdotL;
NdotHV = max(dot(normal, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
// This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
fragColor = color + specular;
fragColor = vec4(fragColor.rgb, fragColor.a * alpha);
fragColor.rgb = fog_Func(fragColor.rgb, 0);
gl_FragColor = fragColor;
}

16
Shaders/text.vert Normal file
View file

@ -0,0 +1,16 @@
#version 120
varying vec4 diffuse_term;
varying vec3 normal;
varying vec4 ecPosition;
void main()
{
gl_Position = ftransform();
ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = gl_NormalMatrix * gl_Normal;
diffuse_term = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
gl_FrontColor = gl_FrontMaterial.emission + gl_FrontMaterial.ambient *
(gl_LightModel.ambient + gl_LightSource[0].ambient);
}