Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 13 April 2014 - 04:14 AM

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, 13 April 2014 - 04:16 AM.


Sponsor:

#2 Ohforf sake   Members   -  Reputation: 1814

Like
0Likes
Like

Posted 14 April 2014 - 06:13 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS