# 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 on other sites
If all you want to do is discard the bottom half of the screen, set up a scissor test, defining your rectangle from (0,0) to (width, height/2).

glScissor (0,0, window_width, window_height/2);

glScissor doc

gl_FragCoord.xy

##### 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 on other sites
Which fog mode? Linear, exp or exp2?

##### Share on other sites
From the orange book...
// Linearfog = ( gl_Fog.end - gl_FogFragCoord ) * gl_Fog.scale;  // Expconst float LOG2E = 1.442695; // = 1 / log( 2 )fog = exp2( -gl_Fog.density * gl_FogFragCoord * LOG2E );  // Exp2const 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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627731
• Total Posts
2978831

• 10
• 9
• 21
• 14
• 12