Home » Community » Forums » OpenGL » GLSL textures and material
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 GLSL textures and material
Post New Topic  Post Reply 
Hi, I am facing this problem: I have a scene where some objects are textured and some have no texture, only material. When I am rendering this scene with GLSL shaders, I am modulating the final fragment color in the fragment shader with texture color:

void main (void)
{
vec4 color, texel;
color = gl_Color;
texel = texture2D(texUnit0, gl_TexCoord[0].xy);
color *= texel;
gl_FragColor = color;
}

But this gives to non-textured objects some portion of texture color and they are darker :( Is it possible to render textured objects with texture and material and non-textured objects only with material color (just like in a fixed func. rendering)?

Thanks a lot.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Of course it is, just for example make two shaders :

Textured :

void main (void) 
{
vec4 color, texel;
color = gl_Color;
texel = texture2D(texUnit0, gl_TexCoord[0].xy);
color *= texel;
gl_FragColor = color;
}


Not-Textured :

void main (void) 
{
vec4 color;
color = gl_Color;
gl_FragColor = color;
}


So, just use different shaders to render different objects.

Sincerely,
Arto Ruotsalainen
Dawn Bringer 3D - Tips & Tricks


 User Rating: 1069   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thaks, I know, that's a solution, but not useful for me. I am using a kind of scene graph - Open Inventor, so the best for me would be to find out in a vertex/fragment shader if a fragment should be textured or not, but how ?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Why don't you add one variable... let's say bool UseTexture, and if you set it to true, fragment shader should use textures, if you set it to false it should not use textures.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

This is another possible solution, but not suitable for me. My scene is created in Open Inventor (high-level 3D graphis extension to OpenGL) and it is a scene graph. Rendering is done through traversing the scene graph from root to children, when OpenGL state is changing.

Your suggested solution is possible, but I would have to change the code inside Open Inventor (that's possible, but I do not want to).

I need some simple solution inside vertex/fragment shader to say, if an object should be textured or not. But I am getting to be worried, this is not possible :(

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Can't you just bind a 1x1 pixel white texture for objects with no texture?

I am sure there is a more elegant solution though.

 User Rating: 1036   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'm not sure, but can't you just then use if (texUnit0) { /* use */ } ?

Sincerely,
Arto Ruotsalainen
Dawn Bringer 3D - Tips & Tricks


 User Rating: 1069   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hi, thanks to all, the solution is here:

if (texUnit0)
doesn't not work, texUnit0 is a texture unit handler and cannot be used like this :(

But the useful trick with white texture by Zymph works !!! (I have placed a 1x1 white texture at the top of the scene graph and I am using

color = gl_Color;
texel = texture2D(texUnit0, gl_TexCoord[0].xy);
color *= texel;

so any non-textured object has correct color now. Thanks all !


 User Rating: 1015    Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: