Jump to content
  • Advertisement
Sign in to follow this  
bencelot

GL_TEXTURE_GEN and fragment shaders.

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

Hey all, I'm starting to use fragment shaders now... and I just have a few questions. Firstly, I think I've run into a problem when combining fragment shaders with texture generation. 1) Is texture generation done in the vertex stage or fragment stage? If it's done in the vertex stage (and I don't have any vertex shaders), does this mean that I can still access the post-generated texels? 2) If so, how? I tried texture2D(shadowTexture,gl_TexCoord[0].st), but that's not giving me expected results. (and yes, I have forwarded the valid texture unit ID to the shader.) 3) When I specify an alpha value for gl_FragColor.. will that alpha value be further used to blend the pixels at all? Or can I do all of that in the fragment shader, and then output whatever alpha value I want? The reason being, I want my fragment shader to output specific alpha values to the framebuffer directly, without altering any of the RGB values.. I need to use these values later, you see. That's all for now :p Thanks, Ben.

Share this post


Link to post
Share on other sites
Advertisement
Ahh, needed to use shadowTexture,gl_TexCoord[1].st (I guess because my shadow casing was in texture unit 1.

So scrap the first 2 questions.. still curious about number 3 though :)

Share this post


Link to post
Share on other sites
After the fragment shader stage, there is the blend stage, so this stage will use the alpha that you give to gl_FragColor.

Share this post


Link to post
Share on other sites
hmm.. and we don't have access to write shaders for this blend stage yet, do we?

Is there someway I can just bypass it? perhaps by setting the BlendFunc to GL_ONE?

Share this post


Link to post
Share on other sites
Yeah, I tried that but it didn't work. Here's where I'm using the shader.

glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glUseProgramObjectARB(images.shadowProgram);
glDisable(GL_BLEND);
map.Draw();
glEnable(GL_BLEND);
glUseProgramObjectARB(0);

And here is shader itself:

uniform sampler2D baseTexture;
uniform sampler2D shadowTexture;
void main() {
vec4 baseColour = texture2D(baseTexture, gl_TexCoord[0].st);
float shadowIntensity = texture2D(shadowTexture, gl_TexCoord[1].st).a;
gl_FragColor = vec4(gl_Color.rgb*baseColour.rgb*(1.0-shadowIntensity/2.0), shadowIntensity);
}

I know that shadowIntensity in the shader is working correctly, because it's altering the RGB values of the fragment properly. Perhaps I can't assign alpha in the way I've done?

Eitherway, one would expect that after doing all of this, any pixels that the map is shown on should have an alpha value of shadowIntensity.. although they don't.. they all have an intensity of 0.

Share this post


Link to post
Share on other sites
My bad.. after doing some more testing.. the alpha set by shadowIntensity WAS coming through.. the problem is that it's coming through in the wrong place. It isn't perpective correct for some reason.

It appears as if I were rendering on a flat 2D plane at z = 0, even though I'm not.

Which is weird, because for the same fragment.. the RGB values will be darkened by this shadowIntensity and then adjusted for perspective, while the alpha values will be set by the shadowIntensity.. but NOT adjusted for perspective.. Does this make any sense at all? Is perspective applied after the fragment shader?

Most confused.

Share this post


Link to post
Share on other sites
Perspective correction is applied to the texture coordinates for each fragment processed so texture2D returns a perspective correct result.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!