shaders x texture information
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!
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;
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;
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?
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?
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. =/
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
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
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!
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement