Jump to content
  • Advertisement
Sign in to follow this  
newbird

OpenGL OpenGL Shaders

This topic is 5002 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

New poster here, but I'm working on my PhD; greetings to all season-tempered vets. I have a quick question for the community. I had a relatively large project which used fixed-functionality multi-texturing for coloring items. In order to have more control over the way the textures were applied, I replaced this fixed-functionality multi-texturing with OpenGL Shading Language vertex and fragment shaders. However, though I mimic the modulate equations specified in the OpenGL standard, the results don't look the same. Previously I was using GL_MODULATE which multiplies each RGBA component for each texture to determine the final fragment color. In my shader (which is attached), I read in the texture correctly, get the texture coordinates correctly, but the equation does not give the same result as the fixed-functionality multi-texturing gave. Do you see anything in the attached vertex and fragment shader code that I could be doing wrong? If I had to guess, I think the differences arise due to truncation error or loss of precision in the pow() function. Does anyone know how GL_MODULATE is implemented in the fragment shader more specifically than: glFragColor *= texture2D(tex0,gl_TexCoord[0].xy) as specified in the GLSL Orange Book (pg.232)? For multitexturing this *should* translate into equation 1 below, but it doesn't. To keep this post from being any longer, I'm pretty sure that everything is correct except the equation itself. Following are the fragment shader equations that have been tried (with comments) where each color variable is a vec4 lookup from the appropriate texture: //OpenGL definition which doesn't get close to approximating the original gl_FragColor = color1*color2*color3; (Equation 1) //Gets much closer, but the colors are still slightly off (enough to be unacceptable) gl_FragColor = pow((color1*color2*color3),(1.0/3.0)); (Equation 2) Thanks in advance, []HoA[]Newbird forever, lol.

Share this post


Link to post
Share on other sites
Advertisement
Maybe this can help:

ShaderGen - Fixed Functionality Shader Generation Tool
http://developer.3dlabs.com/downloads/shadergen/index.htm

Share this post


Link to post
Share on other sites
One of my friends actually sent me this yesterday. It's a very nice tool and can be useful for generating shaders when you don't know what's going on. However, this tool doesn't support multi-texturing which is my whole problem. To be more thorough, the entire fragment shader I'm using is provided below. I only have one color lookup table texture, but I have 3 floating point (between 0.0 and 1.0 of course) RGBA values that I want to use exactly as if they were 3 different textures being used by OpenGL's fixed-functionality multi-texturing. Again, any help would be greatly appreciated.

uniform sampler1D clutTexture;
void main(void) {
vec4 color1 = vec4 (texture1D(clutTexture, gl_TexCoord[0].x));
vec4 color2 = vec4 (texture1D(clutTexture, gl_TexCoord[1].x));
vec4 color3 = vec4 (texture1D(clutTexture, gl_TexCoord[2].x));

gl_FragColor = color1*color2*color3;
//gl_FragColor = pow((color1*color2*color3),(1.0/3.0));
}

Share this post


Link to post
Share on other sites
Total longshot at the moment, but just throwing out something I noticed. Doesn't GL_MODULATE also multiply in the polygon color or material properties? Though if you were using white, this wouldn't be an issue.

Share this post


Link to post
Share on other sites
Its probably not the issue, but worth a mention: according to an nVidia engineer even when you duplicate the stages of the fixed function pipeline on Fx cards and older you won't get the exact same results because back then the code ran on different parts of the card and so different results can be produced.

Like I said, its more than likely not an issue for this but just wanted to share that tidbit of info, because it made a huge difference for me on depth buffer manipulation.

Share this post


Link to post
Share on other sites
Yes, you are right GluCose. But, I am using white and no materials or lighting. I'm aware of the issues that would arise if I used either of these with the posted fragment shader.

The engineering consideration of the fragment shader running on different parts of the card is plausible since I'm using a Quadro FX 1000. I will look into this. I've already emailed 3D labs and Randi Rost (author of OpenGL orange book). jm_hewitt, where did you find that information?

Just a general statement, I personally find the lack of information on OpenGL's shaders for fixed-functionality operation a great shame. The fixed-functionality operations for vertex and fragment shaders should be provided to the community. Programmers want to manipulate, augment, and enhance the functionality of OpenGL, not replace it outright. </rant>

Share this post


Link to post
Share on other sites
u should be able to duplicate it pretty much exactly the only difference is the glsl pipeline uses 32bit throughout (thus is higher precision) but this shouldnt result in anty great difference

check out first how multitexture works
see the opengl spec at www.opengl.org
also goto the nvidia developer site and download some pdf's about multitexture,

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!