1 Reply Latest reply on Jun 17, 2009 1:54 AM by gaurav.garg

    Is there a way of accessing a compoment of float4 by index ( 0 - 3 ) ?

    codeboycjy

      Hi:
          Here is something similar to my task:
          There are 100000 vector3 storing in float4 data, u're asked to pick the ones with the largest compoment larger than 100. The last compoment of each float4 is from 0 to 3 which showes the largest compoment in the vector3.
          here is the only way i've got:

          if( data.w == 0.0f ){ if( data.x > 100 ) { ... } }
          else if ( data.w == 1.0f ) { if( data.y > 100 ) { ...} }
          else if ( data.w == 2.0f ) { if( data.z > 100 ) { ...} }

          Is there a way of accessing the compoment of each element like this:

          if( data[ data.w ] > 100 ) { ...}

          It could be much simpler and much faster than the previous one. The float4 could be accessed this way in the pixel shader. Is there a similar way of doing it in Brook+ to avoid the former method which will cost much.