#246614 - 10/01/08 02:06 PM
Faking gl_FragCoord?
|
Regular Contributor
 
Registered: 03/11/07
Posts: 410
Loc: California
|
Since gl_FragCoord does not work properly on AMD hardware I need to fake it. I am having a little trouble visualizing this. Let's say texcoord is the vec2 I want to write out for gl_FragCoord. The upper-left corner of the screen would be (0,0,z), and the bottom-right corner would be (1,1,z). Here is my light volume vertex shader: varying vec3 texcoord;
void main(void) {
gl_Position = ftransform();
gl_FrontColor = gl_Color;
texcoord=ftransform()
}Now how do I turn the screen position into the gl_FragCoord value?
Edited by Leadwerks (10/01/08 02:30 PM)
|
|
Top
|
|
|
|
#246646 - 10/02/08 05:35 AM
Re: Faking gl_FragCoord?
[Re: Leadwerks]
|
Newbie
Registered: 10/02/08
Posts: 5
Loc: Germany
|
I didn't experience the same issues, but when i got closer to the light-volumes they distorted pretty hard. In the Nvidia-XMas-Tree-Demo the following code was used (at least the same principle), which worked for me too (on my 8600 GT. I don't know if it works on AMD-Cards too).
uniform vec2 buffersize;
varying vec2 fake_FragCoord;
void main( ) {
gl_Position = ftransform( );
gl_Position /= gl_Position.w;
fake_FragCoord = (gl_Position.xy * 0.5 + 0.5) * buffersize;
}
In fact it's the same, but only if I don't do the perspective division in the vertex-shader the distortions appear. If I do it myself everything works fine (except when you a in the light-volumes (but I didn't test if these problems occur if I render only the backfaces). I don't know why that works and I would be happy if someone could explain it^^. EDIT: Forgot the .w and some brackets... EDIT: I watched the video again.. I did have the same issues.
Edited by Pfirsich (10/02/08 10:24 AM)
|
|
Top
|
|
|
|
#246661 - 10/02/08 01:10 PM
Re: Faking gl_FragCoord?
[Re: Leadwerks]
|
Newbie
Registered: 10/02/08
Posts: 5
Loc: Germany
|
It can be written at any time during shader execution. It may also be read back by a vertex shader after being written.
According to the GLSL 1.20.8-specification. And this code works (at least for me). As long as you do the perspective division in the vertex shader yourself, it works. Otherwise it doesn't work. I don't know why...
void main( ) {
gl_Position = ftransform( );
gl_Position /= gl_Position.w;
gl_TexCoord[0] = gl_Position * 0.5 + 0.5;
}
This is the code I use in my deferred-rendering-experiments for acessing the g-buffer-data.
Edited by Pfirsich (10/02/08 01:11 PM)
|
|
Top
|
|
|
|
|
24934 Members
12 Forums
52392 Topics
271545 Posts
Max Online: 482 @ 08/11/08 06:19 PM
|
|
|