Skip to main content
gamedev.net
🔒 Locked

Fragment Program Question

Started by Running_Wolf Oct 21, 2004 at 11:23 PM 6 replies 2.1k views
Original Post
Running_Wolf
Running_Wolf
Is there a way to find the approximate x, y, z values of the fragment that is currently being processed?
L.I.G. == Life Is Good
HellRaiZer
HellRaiZer
I think that fragment.position holds per-fragment window position, if that's what you want. You aren't saying what (x, y, z) values you are searching, so... just a guess.

HellRaiZer
HellRaiZer
Ademan555
Ademan555
i THINK what he means is the world x,y,z coords... i dunno if thats possible though... you obviously are able to find the x,y,z component (relative to the viewpoint) because theres the depth buffer for the z, and x,andy fo r general rasterization

but im guessing he wants world coords

sorry if thats incoherent... im tired...
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
JonnyQuest
JonnyQuest
The best way of doing this is to pass on the world coordinates directly from the vertex program. So you'd just copy the position attribute into a texture coordinate attribute in the vertex program, and then read that out in the fragment program. It'll interpolate the position between the vertices of course, but that shouldn't cause any trouble.

~phil
~phil
Running_Wolf
Running_Wolf
Is that interpolation automatic or do I need to perform the calculations? And since I'm new to fragment programming, how to I pass the position attribute? Thank you.
L.I.G. == Life Is Good
JonnyQuest
JonnyQuest
The interpolation is automatic, just like any other texture coordinate would be automatically interpolated.

You simply copy the contents of the position register to a texture coordinate register of your choice in the vertex program.
With ARB_vertex_program, it'll look something like this:
MOV result.texcoord[n].xyz, vertex.position.xyz;
Assuming that the vertex position is already in world space. If it isn't, you'll have to multiply the position with the world matrix first. n is the index of your texture coordinate vector.

In the fragment program you simply use the value of the texture coordinate register for your calculation. In ARB_fragment_program, that's fragment.texcoord[n].

~phil
~phil
atcdevil
atcdevil
Quote:
Original post by Anonymous Poster

in ARB_fragment_program you can access the window position via

fragment.postion;


Does anyone know how to do this in Cg?


in the fp30 profile you can get the window position by using WPOS:

float4 test(
...
float4 wpos : WPOS
...
) : COLOR {

...

}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.