OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Text colors in shaders


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
wernerM
User


Joined: 06 Feb 2013
Posts: 65

PostPosted: Fri Feb 24, 2017 12:00 pm    Post subject:
Text colors in shaders
Reply with quote

Dear all,

my project needs gl3 features and so I use the following methods:
 
Quote:
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 = new osgViewer::StatsHandler;
Quote:
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:ShockedN); installDefaultShader(stateSet);}
The shaders are really simple:
VERTEX
Quote:
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

0
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

1
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

2
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

3
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

4
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

5
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

6
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

7
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

8
Quote:
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

9
Quote:
view->addEventHandler(sthd);
0
Quote:
view->addEventHandler(sthd);
1
Quote:
view->addEventHandler(sthd);
2
Quote:
view->addEventHandler(sthd);
3
Quote:
view->addEventHandler(sthd);
4
Quote:
view->addEventHandler(sthd);
5
Quote:
view->addEventHandler(sthd);
6
Quote:
view->addEventHandler(sthd);
7
FRAGMENT
Quote:
view->addEventHandler(sthd);
8
Quote:
view->addEventHandler(sthd);
9
Quote:
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
0
Quote:
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
1
Quote:
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
2
Quote:
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
3
Quote:
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
4
That works fine for the graphics but all text is black. Obviously text does not set osg_Color .
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 -

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 796

PostPosted: Fri Feb 24, 2017 12:18 pm    Post subject:
Text colors in shaders
Reply with quote

Am 2/24/2017 um 12:57 PM schrieb Werner Modenbach:
Quote:
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:ShockedN);

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


Quote:
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 -







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
wernerM
User


Joined: 06 Feb 2013
Posts: 65

PostPosted: Fri Feb 24, 2017 2:32 pm    Post subject:
Text colors in shaders
Reply with quote

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:

Quote:


Am 2/24/2017 um 12:57 PM schrieb Werner Modenbach:
Quote:
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:ShockedN);

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


Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
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: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11235

PostPosted: Fri Feb 24, 2017 3:12 pm    Post subject:
Text colors in shaders
Reply with quote

On 24 February 2017 at 14:30, Werner Modenbach
<> wrote:
Quote:
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.

If you build the OSG against the GL3 core profile it maps the texture
format to GL_RED rather than GL_ALPHA as the later is no longer
supported. The graphics hardware doesn't expand GL_RED in the same
way as GL_ALPHA so it can cause problems. It's a bit of pain having
GL pull the rug from GL_ALPHA as it has a particularly useful mapping.
Potentially one could use texture swizzle to get round this but it's
not support on all GL versions.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
wernerM
User


Joined: 06 Feb 2013
Posts: 65

PostPosted: Fri Feb 24, 2017 3:18 pm    Post subject:
Text colors in shaders
Reply with quote

Hi Robert,

thanks for the good explanations - as we are used from your side Smile
I cannot switch completely to gl3 because I have customers whose hardware/driver doesn't support it
So at the start of the application I analyze it and use the
Quote:
camera->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(useGL3);
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

accordingly. It's for sure a burden but what can I do?

Thanks for your excellent support!

- Werner -

Am 24.02.2017 um 16:09 schrieb Robert Osfield:

Quote:
Quote:
On 24 February 2017 at 14:30, Werner Modenbach
<> (
Only registered users can see emails on this board!
Get registred or enter the forums!
) wrote:
Quote:
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.

If you build the OSG against the GL3 core profile it maps the texture
format to GL_RED rather than GL_ALPHA as the later is no longer
supported. The graphics hardware doesn't expand GL_RED in the same
way as GL_ALPHA so it can cause problems. It's a bit of pain having
GL pull the rug from GL_ALPHA as it has a particularly useful mapping.
Potentially one could use texture swizzle to get round this but it's
not support on all GL versions.

Robert.
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
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: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11235

PostPosted: Fri Feb 24, 2017 3:36 pm    Post subject:
Text colors in shaders
Reply with quote

On 24 February 2017 at 15:15, Werner Modenbach
<> wrote:
Quote:
Hi Robert,

thanks for the good explanations - as we are used from your side Smile
I cannot switch completely to gl3 because I have customers whose
hardware/driver doesn't support it
So at the start of the application I analyze it and use the

camera->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(useGL3);
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);

accordingly. It's for sure a burden but what can I do?

I don't know witthout testing your specific shader and scene graph setup.

For your own work, if you can't switching completely to GL3 why not
just use standard OSG build and not bother with the aliasing. For
decent GL drivers you should get access to modern GL features via the
OSG extension system, you don't need to go explicitly enabling GL3/GL4
features. the only exception is OSX and their CL3 core profile mess.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts "Memory: Colors" game from ... kornerr General 3 Sat Oct 28, 2017 11:19 am View latest post
No new posts Major changes to osgText merged into ... robertosfield General 0 Thu Oct 26, 2017 5:30 pm View latest post
No new posts Problem With Osg Texture Colors! Bobykhani General [forum] 1 Tue Oct 10, 2017 8:20 am View latest post
No new posts Transform matrix as Uniform to shaders freqfly General 3 Thu Oct 05, 2017 4:19 am View latest post
No new posts How to pre-compile shaders before act... kornerr General 1 Thu Sep 28, 2017 8:42 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP