Browse Source

added Smoothstep AGAL operation (#510)

Klug76 6 năm trước cách đây
mục cha
commit
db544b04b9
2 tập tin đã thay đổi với 22 bổ sung0 xóa
  1. 19 0
      hxsl/AgalOut.hx
  2. 3 0
      hxsl/Flatten.hx

+ 19 - 0
hxsl/AgalOut.hx

@@ -751,6 +751,25 @@ class AgalOut {
 			op(OAbs(r2, r2));
 			op(OAdd(r, r, r2));
 			return r;
+		case [Smoothstep, [e0, e1, x]]:
+			//:x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+			var edge0 = expr(e0);
+			var edge1 = expr(e1);
+			var r = allocReg(ret);
+			var t = allocReg(ret);
+			op(OMov(r, expr(x)));
+			op(OMov(t, edge1));
+			op(OSub(r, r, edge0));
+			op(OSub(t, t, edge0));
+			op(ORcp(t, t));
+			op(OMul(r, r, t));
+			op(OSat(r, r));
+			//:return x * x * (3 - 2 * x);
+			op(OMul(t, r, getConst(2.0)));
+			op(OMul(r, r, r));
+			op(OSub(t, getConst(3.0), t));
+			op(OMul(r, r, t));
+			return r;
 		default:
 		}
 

+ 3 - 0
hxsl/Flatten.hx

@@ -184,6 +184,9 @@ class Flatten {
 			case UvToScreen:
 				allocConsts([2,-2], e.p);
 				allocConsts([-1,1], e.p);
+			case Smoothstep:
+				allocConst(2.0, e.p);
+				allocConst(3.0, e.p);
 			default:
 			}
 		case TCall( { e : TGlobal(Vec4) }, [ { e : TVar( { kind : Global | Param | Input | Var } ), t : TVec(3, VFloat) }, { e : TConst(CInt(1)) } ]):