Retrieveing the on-screen location of a fragment

Started by
5 comments, last by Kalidor 17 years, 9 months ago
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?
Advertisement
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
Holy crap I started a blog - http://unobvious.typepad.com/
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?
Which fog mode? Linear, exp or exp2?
From the orange book...
Fragment shader:
// 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.
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.

This topic is closed to new replies.

Advertisement