Sign in to follow this  
Eldritch

Retrieveing the on-screen location of a fragment

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this