⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slang_common_builtin.gc

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 GC
📖 第 1 页 / 共 3 页
字号:
vec4 sqrt(const vec4 v){   float r;   __asm float_rsq r, v.x;   __asm float_rcp __retVal.x, r;   __asm float_rsq r, v.y;   __asm float_rcp __retVal.y, r;   __asm float_rsq r, v.z;   __asm float_rcp __retVal.z, r;   __asm float_rsq r, v.w;   __asm float_rcp __retVal.w, r;}//// inversesqrtfloat inversesqrt(const float x){   __asm float_rsq __retVal.x, x;}vec2 inversesqrt(const vec2 v){   __asm float_rsq __retVal.x, v.x;   __asm float_rsq __retVal.y, v.y;}vec3 inversesqrt(const vec3 v){   __asm float_rsq __retVal.x, v.x;   __asm float_rsq __retVal.y, v.y;   __asm float_rsq __retVal.z, v.z;}vec4 inversesqrt(const vec4 v){   __asm float_rsq __retVal.x, v.x;   __asm float_rsq __retVal.y, v.y;   __asm float_rsq __retVal.z, v.z;   __asm float_rsq __retVal.w, v.w;}//// normalizefloat normalize(const float x){   __retVal = 1.0;}vec2 normalize(const vec2 v){   const float s = inversesqrt(dot(v, v));   __asm vec4_multiply __retVal.xy, v, s;}vec3 normalize(const vec3 v){//   const float s = inversesqrt(dot(v, v));//   __retVal = v * s;// XXX note, we _could_ use __retVal.w instead of tmp and and save a// register, but that's actually a compilation error because v is a vec3// and the .w suffix is illegal.  Oh well.   float tmp;   __asm vec3_dot tmp, v, v;   __asm float_rsq tmp, tmp;   __asm vec4_multiply __retVal.xyz, v, tmp;}vec4 normalize(const vec4 v){   float tmp;   __asm vec4_dot tmp, v, v;   __asm float_rsq tmp, tmp;   __asm vec4_multiply __retVal.xyz, v, tmp;}//// 8.3 Common Functions////// absfloat abs(const float a){   __asm vec4_abs __retVal, a;}vec2 abs(const vec2 a){   __asm vec4_abs __retVal.xy, a;}vec3 abs(const vec3 a){   __asm vec4_abs __retVal.xyz, a;}vec4 abs(const vec4 a){   __asm vec4_abs __retVal, a;}//// signfloat sign(const float x){   float p, n;   __asm vec4_sgt p, x, 0.0;            // p = (x > 0)   __asm vec4_sgt n, 0.0, x;            // n = (x < 0)   __asm vec4_subtract __retVal, p, n;  // sign = p - n}vec2 sign(const vec2 v){   vec2 p, n;   __asm vec4_sgt p.xy, v, 0.0;   __asm vec4_sgt n.xy, 0.0, v;   __asm vec4_subtract __retVal.xy, p, n;}vec3 sign(const vec3 v){   vec3 p, n;   __asm vec4_sgt p.xyz, v, 0.0;   __asm vec4_sgt n.xyz, 0.0, v;   __asm vec4_subtract __retVal.xyz, p, n;}vec4 sign(const vec4 v){   vec4 p, n;   __asm vec4_sgt p, v, 0.0;   __asm vec4_sgt n, 0.0, v;   __asm vec4_subtract __retVal, p, n;}//// floorfloat floor(const float a){   __asm vec4_floor __retVal, a;}vec2 floor(const vec2 a){   __asm vec4_floor __retVal.xy, a;}vec3 floor(const vec3 a){   __asm vec4_floor __retVal.xyz, a;}vec4 floor(const vec4 a){   __asm vec4_floor __retVal, a;}//// ceilfloat ceil(const float a){   // XXX this could be improved   float b = -a;   __asm vec4_floor b, b;   __retVal = -b;}vec2 ceil(const vec2 a){   vec2 b = -a;   __asm vec4_floor b, b;   __retVal.xy = -b;}vec3 ceil(const vec3 a){   vec3 b = -a;   __asm vec4_floor b, b;   __retVal.xyz = -b;}vec4 ceil(const vec4 a){   vec4 b = -a;   __asm vec4_floor b, b;   __retVal = -b;}//// fractfloat fract(const float a){   __asm vec4_frac __retVal, a;}vec2 fract(const vec2 a){   __asm vec4_frac __retVal.xy, a;}vec3 fract(const vec3 a){   __asm vec4_frac __retVal.xyz, a;}vec4 fract(const vec4 a){   __asm vec4_frac __retVal, a;}//// mod  (very untested!)float mod(const float a, const float b){    float oneOverB;    __asm float_rcp oneOverB, b;    __retVal = a - b * floor(a * oneOverB);}vec2 mod(const vec2 a, const float b){    float oneOverB;    __asm float_rcp oneOverB, b;    __retVal.xy = a - b * floor(a * oneOverB);}vec3 mod(const vec3 a, const float b){    float oneOverB;    __asm float_rcp oneOverB, b;    __retVal.xyz = a - b * floor(a * oneOverB);}vec4 mod(const vec4 a, const float b){    float oneOverB;    __asm float_rcp oneOverB, b;    __retVal = a - b * floor(a * oneOverB);}vec2 mod(const vec2 a, const vec2 b){    vec2 oneOverB;    __asm float_rcp oneOverB.x, b.x;    __asm float_rcp oneOverB.y, b.y;    __retVal = a - b * floor(a * oneOverB);}vec3 mod(const vec3 a, const vec3 b){    vec3 oneOverB;    __asm float_rcp oneOverB.x, b.x;    __asm float_rcp oneOverB.y, b.y;    __asm float_rcp oneOverB.z, b.z;    __retVal = a - b * floor(a * oneOverB);}vec4 mod(const vec4 a, const vec4 b){    vec4 oneOverB;    __asm float_rcp oneOverB.x, b.x;    __asm float_rcp oneOverB.y, b.y;    __asm float_rcp oneOverB.z, b.z;    __asm float_rcp oneOverB.w, b.w;    __retVal = a - b * floor(a * oneOverB);}//// minfloat min(const float a, const float b){   __asm vec4_min __retVal, a, b;}vec2 min(const vec2 a, const vec2 b){   __asm vec4_min __retVal.xy, a.xy, b.xy;}vec3 min(const vec3 a, const vec3 b){   __asm vec4_min __retVal.xyz, a.xyz, b.xyz;}vec4 min(const vec4 a, const vec4 b){   __asm vec4_min __retVal, a, b;}vec2 min(const vec2 a, const float b){   __asm vec4_min __retVal, a.xy, b;}vec3 min(const vec3 a, const float b){   __asm vec4_min __retVal, a.xyz, b;}vec4 min(const vec4 a, const float b){   __asm vec4_min __retVal, a, b;}//// maxfloat max(const float a, const float b){   __asm vec4_max __retVal, a, b;}vec2 max(const vec2 a, const vec2 b){   __asm vec4_max __retVal.xy, a.xy, b.xy;}vec3 max(const vec3 a, const vec3 b){   __asm vec4_max __retVal.xyz, a.xyz, b.xyz;}vec4 max(const vec4 a, const vec4 b){   __asm vec4_max __retVal, a, b;}vec2 max(const vec2 a, const float b){   __asm vec4_max __retVal, a.xy, b;}vec3 max(const vec3 a, const float b){   __asm vec4_max __retVal, a.xyz, b;}vec4 max(const vec4 a, const float b){   __asm vec4_max __retVal, a, b;}//// clampfloat clamp(const float val, const float minVal, const float maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec2 clamp(const vec2 val, const float minVal, const float maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec3 clamp(const vec3 val, const float minVal, const float maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec4 clamp(const vec4 val, const float minVal, const float maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec2 clamp(const vec2 val, const vec2 minVal, const vec2 maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec3 clamp(const vec3 val, const vec3 minVal, const vec3 maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}vec4 clamp(const vec4 val, const vec4 minVal, const vec4 maxVal){   __asm vec4_clamp __retVal, val, minVal, maxVal;}//// mixfloat mix(const float x, const float y, const float a){   __asm vec4_lrp __retVal, a, y, x;}vec2 mix(const vec2 x, const vec2 y, const float a){   __asm vec4_lrp __retVal, a, y, x;}vec3 mix(const vec3 x, const vec3 y, const float a){   __asm vec4_lrp __retVal, a, y, x;}vec4 mix(const vec4 x, const vec4 y, const float a){   __asm vec4_lrp __retVal, a, y, x;}vec2 mix(const vec2 x, const vec2 y, const vec2 a){   __asm vec4_lrp __retVal, a, y, x;}vec3 mix(const vec3 x, const vec3 y, const vec3 a){   __asm vec4_lrp __retVal, a, y, x;}vec4 mix(const vec4 x, const vec4 y, const vec4 a){   __asm vec4_lrp __retVal, a, y, x;}//// stepfloat step(const float edge, const float x){   __asm vec4_sge __retVal, x, edge;}vec2 step(const vec2 edge, const vec2 x){   __asm vec4_sge __retVal.xy, x, edge;}vec3 step(const vec3 edge, const vec3 x){   __asm vec4_sge __retVal.xyz, x, edge;}vec4 step(const vec4 edge, const vec4 x){   __asm vec4_sge __retVal, x, edge;}vec2 step(const float edge, const vec2 v){   __asm vec4_sge __retVal.xy, v, edge;}vec3 step(const float edge, const vec3 v){   __asm vec4_sge __retVal.xyz, v, edge;}vec4 step(const float edge, const vec4 v){   __asm vec4_sge __retVal, v, edge;}//// smoothstepfloat smoothstep(const float edge0, const float edge1, const float x){    float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);    return t * t * (3.0 - 2.0 * t);}vec2 smoothstep(const vec2 edge0, const vec2 edge1, const vec2 v){   vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}vec3 smoothstep(const vec3 edge0, const vec3 edge1, const vec3 v){   vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}vec4 smoothstep(const vec4 edge0, const vec4 edge1, const vec4 v){   vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}vec2 smoothstep(const float edge0, const float edge1, const vec2 v){   vec2 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}vec3 smoothstep(const float edge0, const float edge1, const vec3 v){   vec3 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}vec4 smoothstep(const float edge0, const float edge1, const vec4 v){   vec4 t = clamp((v - edge0) / (edge1 - edge0), 0.0, 1.0);   return t * t * (3.0 - 2.0 * t);}//// 8.4 Geometric Functions////// lengthfloat length(const float x){   return abs(x);}float length(const vec2 v){   float r;   const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y   __asm float_rsq r, p;           // r = 1 / sqrt(p)   __asm float_rcp __retVal.x, r;  // retVal = 1 / r}float length(const vec3 v){   float r;   const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y + v.z * v.z   __asm float_rsq r, p;           // r = 1 / sqrt(p)   __asm float_rcp __retVal, r;    // retVal = 1 / r}float length(const vec4 v){   float r;   const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y + ...   __asm float_rsq r, p;           // r = 1 / sqrt(p)   __asm float_rcp __retVal, r;    // retVal = 1 / r}//// distancefloat distance(const float x, const float y){   const float d = x - y;   __retVal = length(d);}float distance(const vec2 v, const vec2 u){   const vec2 d2 = v - u;   __retVal = length(d2);}float distance(const vec3 v, const vec3 u){   const vec3 d3 = v - u;   __retVal = length(d3);}float distance(const vec4 v, const vec4 u){   const vec4 d4 = v - u;   __retVal = length(d4);}//// crossvec3 cross(const vec3 v, const vec3 u){   __asm vec3_cross __retVal.xyz, v, u;}//// faceforwardfloat faceforward(const float N, const float I, const float Nref){    // this could probably be done better    const float d = dot(Nref, I);    float s;    __asm vec4_sgt s, 0.0, d;  // s = (0.0 > d) ? 1 : 0    return mix(-N, N, s);}vec2 faceforward(const vec2 N, const vec2 I, const vec2 Nref){    // this could probably be done better    const float d = dot(Nref, I);    float s;    __asm vec4_sgt s, 0.0, d;  // s = (0.0 > d) ? 1 : 0    return mix(-N, N, s);}vec3 faceforward(const vec3 N, const vec3 I, const vec3 Nref){    // this could probably be done better    const float d = dot(Nref, I);    float s;    __asm vec4_sgt s, 0.0, d;  // s = (0.0 > d) ? 1 : 0    return mix(-N, N, s);}vec4 faceforward(const vec4 N, const vec4 I, const vec4 Nref){    // this could probably be done better    const float d = dot(Nref, I);    float s;    __asm vec4_sgt s, 0.0, d;  // s = (0.0 > d) ? 1 : 0    return mix(-N, N, s);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -