Jump to content
  • Advertisement
Sign in to follow this  
Eldritch

Retrieveing the on-screen location of a fragment

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

Is it possible to retrieve the on-screen position of a fragment when using GLSL? For example, if I want only the fragments that are between 0 and window_height/2 along the y-axis on the screen to be drawn and the rest to be skipped (the discard command). Would this be possible to do?

Share this post


Link to post
Share on other sites
Advertisement
Great, gl_FragCoord works! Thanks a bunch! :)

It'll help me replicate the GL_FOG stuff that fixed-function rendering has but which is overridden with shaders.

Any insight into how to emulate the fog so it look similar to the fog in regular mode?

Also, is it possible for a shader surface to be rendered with transparency, or is that an advanced procedure where I need to do it multi-pass?

Share this post


Link to post
Share on other sites
From the orange book...
Fragment shader:

// Linear
fog = ( gl_Fog.end - gl_FogFragCoord ) * gl_Fog.scale;

// Exp
const float LOG2E = 1.442695; // = 1 / log( 2 )
fog = exp2( -gl_Fog.density * gl_FogFragCoord * LOG2E );

// Exp2
const float LOG2E = 1.442695; // = 1 / log( 2 )
fog = exp2( -gl_Fog.density * gl_Fog.density *
gl_FogFragCoord * gl_FogFragCoord * LOG2E );


Where you set the gl_FogFragCoord in the vertex shader to the length from the eye position to the vertex position (or to gl_FogCoord if using fog coordinates).

I have not had 100% luck in getting this working so I would be interested to hear of any success you have.

Share this post


Link to post
Share on other sites
Quote:
Original post by Eldritch
...Also, is it possible for a shader surface to be rendered with transparency, or is that an advanced procedure where I need to do it multi-pass?
Yep, it's definitely possible. Blending is completely separate from the programmable pipeline so you use it in exactly the same way as if you weren't using shaders.

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!