[osg-users] Text colors in shaders

Werner Modenbach Werner.Modenbach at texion.eu
Fri Feb 24 06:30:15 PST 2017


Hi Sebastian,

that's great. It works with the shader you suggested.
Strange is, that just using vertex color doesn't work. It seems alpha is 
set to transparent (0).
Also a texture is set but only alpha has a meaning. Texture color is black.
That looks odd to me.

But anyway, I'm happy now.

- Werner -

Am 24.02.2017 um 13:16 schrieb Sebastian Messerschmidt:
>
>
> 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 
>>
>>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-- 
*TEXION Software Solutions, Rotter Bruch 26a, D-52068 Aachen*
Phone: +49 241 475757-0
Fax: +49 241 475757-29
Web: http://texion.eu
eMail: info at texion.eu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170224/77c741db/attachment-0003.htm>


More information about the osg-users mailing list