• Advertisement
Sign in to follow this  

Formular to get Frumstum-Index from Vector for 2D-Cube-Mapping

This topic is 1376 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

I'm working on a formular to calculate the index for the frustum of a 2D-Point-Light.

My Light-System is rendering the Scene into 4 1D-Textures: Right, Left, Top and Bottom.

 

Now, in the fragment shader I want to query the index for the frustum corresponding to the fragment position in light-space,

so I know which depth texture I have to sample.

 

I got one that works, but it's very complicated.

 

 

0004.png

Or should I just do a series of "if" statements.

My concern with that is, that inside a warp, only the body of one if-statement can be entered, which leaves all fragments idling, if they have different frustum.

Edited by stefthedrummer

Share this post


Link to post
Share on other sites
Advertisement
How about:
absMax = max(abs(p.x), abs(p.y))

int index;
if (p.x == absMax) index = 0; else
if (-p.x == absMax) index = 1; else
if (p.y == absMax) index = 2; else
   index = 3;
This should compile to a number of comparissons that all threads of the warp will perform equally, followed by four conditional assignments. If not, it should be possible to replace them with step functions like this:
 
absMax = max(abs(p.x), abs(p.y))

float findex = 3.0f;
findex = mix(findex, 0.0f, step(absMax, p.x));
findex = mix(findex, 1.0f, step(absMax, -p.x));
findex = mix(findex, 2.0f, step(absMax, p.y));
But I think that's more expensive then using if.


I guess it's one of the cases where you wish for a way to inspect the produced assembly of a shader...



As a side question, couldn't you render the depths into one big texture four times as long (concatenated) so you don't have to compute an index at all? Otherwise you will get the divergences anyways when sampling different textures.

Share this post


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

  • Advertisement