|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| GLSL textures and material |
|
![]() Shamot Member since: 11/10/2006 From: Brno, Czech Republic |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Arex Member since: 7/1/2004 From: Helsinki, Finland |
||||
|
|
||||
| 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 |
||||
|
||||
![]() Shamot Member since: 11/10/2006 From: Brno, Czech Republic |
||||
|
|
||||
| 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 ? |
||||
|
||||
![]() Srki_82 Member since: 7/14/2004 From: Fed Rep Yugoslavia |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Shamot Member since: 11/10/2006 From: Brno, Czech Republic |
||||
|
|
||||
| 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 :( |
||||
|
||||
![]() Zymph Member since: 8/28/2006 From: Mumbai, India |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Arex Member since: 7/1/2004 From: Helsinki, Finland |
||||
|
|
||||
| I'm not sure, but can't you just then use if (texUnit0) { /* use */ } ? Sincerely, Arto Ruotsalainen Dawn Bringer 3D - Tips & Tricks |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| 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 ! |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|