Jump to content
  • Advertisement
Sign in to follow this  
Running_Wolf

Fragment Program Question

This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

in ARB_fragment_program you can access the window position via

fragment.postion;


Does anyone know how to do this in Cg?

Share this post


Link to post
Share on other sites
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 {

...

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!