LYGIA Shader Library

taylorInvSqrt (lygia/math/taylorInvSqrt)

Fast, accurate inverse square root.

Use:

<float|vec2|vec3|vec4> taylorInvSqrt(<float|vec2|vec3|vec4> x)

Check it on Github


#ifndef FNC_TAYLORINVSQRT
#define FNC_TAYLORINVSQRT
float taylorInvSqrt(in float r) { return 1.79284291400159 - 0.85373472095314 * r; }
vec2 taylorInvSqrt(in vec2 r) { return 1.79284291400159 - 0.85373472095314 * r; }
vec3 taylorInvSqrt(in vec3 r) { return 1.79284291400159 - 0.85373472095314 * r; }
vec4 taylorInvSqrt(in vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
#endif

Use:

<float|float2|float3|float4> taylorInvSqrt(<float|float2|float3|float4> x)

Check it on Github


#ifndef FNC_TAYLORINVSQRT
#define FNC_TAYLORINVSQRT
float taylorInvSqrt(in float r) { return 1.79284291400159 - 0.85373472095314 * r; }
float2 taylorInvSqrt(in float2 r) { return 1.79284291400159 - 0.85373472095314 * r; }
float3 taylorInvSqrt(in float3 r) { return 1.79284291400159 - 0.85373472095314 * r; }
float4 taylorInvSqrt(in float4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
#endif

Use:

<float|float2|float3|float4> taylorInvSqrt(<float|float2|float3|float4> x)

Check it on Github


#ifndef FNC_TAYLORINVSQRT
#define FNC_TAYLORINVSQRT
float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; }
float2 taylorInvSqrt(float2 r) { return 1.79284291400159 - 0.85373472095314 * r; }
float3 taylorInvSqrt(float3 r) { return 1.79284291400159 - 0.85373472095314 * r; }
float4 taylorInvSqrt(float4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
#endif

Check it on Github


fn taylorInvSqrt(r: f32) -> f32 { return 1.79284291400159 - 0.85373472095314 * r; }
fn taylorInvSqrt2(r: vec2f) -> vec2f { return 1.79284291400159 - 0.85373472095314 * r; }
fn taylorInvSqrt3(r: vec3f) -> vec3f { return 1.79284291400159 - 0.85373472095314 * r; }
fn taylorInvSqrt4(r: vec4f) -> vec4f { return 1.79284291400159 - 0.85373472095314 * r; }

Dependencies:

Use:

<float|float2|float3|float4> taylorInvSqrt(<float|float2|float3|float4> x)

Check it on Github



#ifndef FNC_TAYLORINVSQRT
#define FNC_TAYLORINVSQRT
inline __host__ __device__ float taylorInvSqrt(float r) { return 1.79284291400159f - 0.85373472095314f * r; }
inline __host__ __device__ float2 taylorInvSqrt(const float2& r) { return 1.79284291400159f - 0.85373472095314f * r; }
inline __host__ __device__ float3 taylorInvSqrt(const float3& r) { return 1.79284291400159f - 0.85373472095314f * r; }
inline __host__ __device__ float4 taylorInvSqrt(const float4& r) { return 1.79284291400159f - 0.85373472095314f * r; }
#endif

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository