Jump to content
  • Advertisement
Sign in to follow this  
hemir17

OpenGL shaders x texture information

This topic is 3654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! This is my first post here. Now I'm quite a noob in OpenGL SL, so I'm starting with a noob question. =P I need to get the RGB pixel value in texture file. I have a texture image bmp file (1024x1024) with some areas black and others white, depends on that a different behavior takes place for each color. Now I have this: vertex program: varying vec2 v_vTexCoord; v_vTexCoord = gl_MultiTexCoord0.xy; fragment program: uniform sampler2D u_sHairTexture; uniform vec4 u_vHairColor; hairColor = texture2D(u_sHairTexture, v_vTexCoord); gl_FragColor = vec4(fakefurLighting(vNormal, vTangent, vEyeDir, vLightDir, vLightDir2),1.0); I've implemented a RGB bmp loader code, so I know there are some pixels from texture image with values R=255,G=255,B=255. I need to get them, but I don't know how to do it. By the way, I'm using RederMonkey 1.81v. Thanks in advance, folks!

Share this post


Link to post
Share on other sites
Advertisement
hairColor = texture2D(u_sHairTexture, v_vTexCoord);

It returns a vec4, normalized values if the texture is GL_RGB8 or GL_RGBA8. This means values are in the 0.0 to 1.0 range.
Just do this

vec4 hairColor2;
hairColor2 = hairColor * 255.0;

Share this post


Link to post
Share on other sites
Thanks, V-man. I did exactly what you said, but I'm still not able to get the pixels values from texture. I've tried this:

vec4 hairColor;
vec4 hairColor2;

void main(void)
{

hairColor = texture2D(u_sHairTexture, v_vTexCoord);
hairColor2 = hairColor * 255.0;

if (hairColor2 == vec4(0.0, 0.0, 0.0, 0.0))
gl_FragColor = vec4(255.0, 255.0, 255.0, 0.0);
else
gl_FragColor = vec4(fakefurLighting(vNormal, vTangent, vEyeDir, vLightDir, vLightDir2),1.0);

}

I was trying to paint the pixels with values R=0.0, G=0.0, B=0.0 with R=255.0, G=255.0, B=255.0. Is there anything wrong with the "if"? Is that the right way to do this comparison?

Share this post


Link to post
Share on other sites
The code is compiled successfully, and I'm able to run it (the model is drew on the screen with the selected texture). But it isn't painted as I'd expected. I've created a texture with black and white parts, I'm trying to exchange the black pixels from texture by white pixels or vice versa, however nothing changes in the texture used on the model. =/

Share this post


Link to post
Share on other sites
Try to set alpha to 0.0

hairColor2.a=0.0;

Btw, if you output 255.0
gl_FragColor = vec4(255.0, 255.0, 255.0, 0.0);

and your framebuffer is some fixed format like RGBA8, then it will get clamped to 1.0
I don't see a reason for you to multiply by 255.0

Share this post


Link to post
Share on other sites
Finally it worked! :D

Thanks, V-man! I was messing up everything. Here is the code:

hairColor = texture2D(u_sHairTexture, v_vTexCoord);
hairColor2 = hairColor * 255.0;

if ((hairColor2.x == 255.0) && (hairColor2.y == 255.0) && (hairColor2.z == 255.0))
gl_FragColor = vec4(1.0, 0.9, 0.22, 0.0);
else
gl_FragColor = vec4(fakefurLighting(vNormal, vTangent, vEyeDir, vLightDir, vLightDir2),1.0);

I should have noticed before that gl_FragColor must to receive RGB values between 0.0 and 1.0. Now it works fine!

I really appreciate all the tips and information, V-man! Thanks a lot!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!