[osg-users] Text colors in shaders

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Fri Feb 24 04:16:21 PST 2017



Am 2/24/2017 um 12:57 PM schrieb Werner Modenbach:
> Dear all,
>
> my project needs gl3 features and so I use the following methods:
>
>
> camera->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(useGL3);
>
> camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);
>
> Of course I need my own shaders then.
> But I also like having built-in functionality like StatsHandler.
> To set a simple shader for the StatsHandlers camera I do like that:
>
> osgViewer::StatsHandler*sthd=newosgViewer::StatsHandler;
>
> view->addEventHandler(sthd);
>
> if(useGL3){
> stateSet=sthd->getCamera()->getOrCreateStateSet();
>
> stateSet->getOrCreateUniform(BASE_TEXTURE_UNIFORM,osg::Uniform::INT_SAMPLER_2D)->set(BASE_TEXTURE_UNIT);
>
> stateSet->setTextureAttributeAndModes(BASE_TEXTURE_UNIT,textur_weiss.get(),osg::StateAttribute::ON);
>
> installDefaultShader(stateSet);
>
> }
>
> The shaders are really simple:
> VERTEX
>
> uniformmat4osg_ModelViewProjectionMatrix;
> uniformmat4osg_ModelViewMatrix;
>
> uniformmat3osg_NormalMatrix;
>
> uniformvec3lightPosition0=vec3(0.0f,0.0f,1.0f);
>
> invec4osg_Vertex;
>
> invec4osg_Normal;
>
> invec4osg_Color;
>
> invec4osg_MultiTexCoord0;
>
> outvec3normal;
>
> outvec3lightDir;
>
> outvec4vertexColor;
>
> outvec2textureCoord;
>
> voidmain(){
>
> normal=normalize(osg_NormalMatrix*osg_Normal.xyz);
>
> vec3vertexPos=vec3(osg_ModelViewMatrix*osg_Vertex);
>
> lightDir=normalize(lightPosition0-vertexPos);
>
> vertexColor=osg_Color;
>
> textureCoord=osg_MultiTexCoord0.xy;
>
> gl_Position=osg_ModelViewProjectionMatrix*osg_Vertex;
>
> }
>
>
> FRAGMENT
>
> uniformsampler2DbaseTexture;
>
> invec3normal;
> invec3lightDir;
>
> invec4vertexColor;
>
> invec2textureCoord;
>
> outvec4fragData;
>
> voidmain(){
>
>     vec4textureColor=texture2D(baseTexture,textureCoord);
> fragData=vertexColor*textureColor;
>
> }
>
>
> That works fine for the graphics but all text is black. Obviously text
> does not set osg_Color .

osg_Color is an alias for the color-vertex attribute. Colors are set in
void Text::drawForegroundText ~line 1628. So there should be colors.

My fragment shader looks like this:

#version 440
#extension GL_ARB_enhanced_layouts : enable
#extension GL_ARB_separate_shader_objects : enable

layout (location=0) out vec4 FragmentData;

layout(location=1) in block
{
	mediump vec2 tex_coord;
	mediump vec4 color;
} In;


uniform sampler2D osg_Texture;

void main()
{

	vec4 diffuse_color = In.color;

	diffuse_color *=  texture2D(osg_Texture, In.tex_coord).a;

	FragmentData = diffuse_color;
}

which seems to work. As you can see I'm using the alpha channel only.

Cheers
Sebastian


> Unfortunately I failed discovering the reason in the sources of osg.
>
> Can anyone give me a hint on how to solve this?
>
> Many thanks in advance
>
> - Werner -
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list