spectral

SIMD & conditional expressions

Discussion created by spectral on Aug 31, 2011
Latest reply on Sep 1, 2011 by spectral
Optimization questions with float4 ?

Hi,

I have some code that currently use 'float' and would like to use 'float4'. But, there is a condition into this function. Is there a solution for this kind of case ?

I join the code, but how will react the 'sqrt' with a negative value or zero value ! Do you think that there is a faster way to do this (Less instruction, lesss divergence) ?

Thanks

 

 

float fresnel_dielectric(float cosi, float eta) { cosi = clamp(cosi, -1.f, 1.f); float c = fabs(cosi); float g = eta * eta - 1 + c * c; if (g > 0) { g = sqrt(g); float A = (g - c) / (g + c); float B = (c * (g + c) - 1) / (c * (g - c) + 1); return 0.5f * A * A * (1 + B * B); } return 1.f; // TIR (no refracted component) } float4 fresnel_dielectric4(float cosi, float4 eta) { cosi = clamp(cosi, -1.f, 1.f); float c = fabs(cosi); float4 g = eta * eta - 1 + c * c; g = sqrt(g); float4 A = (g - c) / (g + c); float4 B = (c * (g + c) - 1) / (c * (g - c) + 1); float4 fresnel 0.5f * A * A * (1 + B * B); return (float4)((g.x > 0) ? fresnel.x : 1.f, (g.x > 0) ? fresnel.x : 1.f, (g.x > 0) ? fresnel.x : 1.f, (g.x > 0) ? fresnel.x : 1.f) }

Outcomes