Przeglądaj źródła

Add invLerp(v, a, b) to hxsl

borisrp 7 miesięcy temu
rodzic
commit
a321da5016
4 zmienionych plików z 7 dodań i 0 usunięć
  1. 1 0
      hxsl/Ast.hx
  2. 2 0
      hxsl/Checker.hx
  3. 2 0
      hxsl/GlslOut.hx
  4. 2 0
      hxsl/HlslOut.hx

+ 1 - 0
hxsl/Ast.hx

@@ -233,6 +233,7 @@ enum TGlobal {
 	Max;
 	Clamp;
 	Mix;
+	InvLerp;
 	Step;
 	Smoothstep;
 	Length;

+ 2 - 0
hxsl/Checker.hx

@@ -106,6 +106,8 @@ class Checker {
 						r.push( { args : [ { name : "x", type : t }, { name : "y", type : t }, { name : "a", type : TFloat } ], ret : t } );
 				}
 				r;
+			case InvLerp:
+				[ { args : [{ name : "a", type : TFloat }, { name : "x", type : TFloat }, { name : "y", type : TFloat } ], ret : TFloat } ];
 			case Step:
 				var r = [];
 				for( t in genType ) {

+ 2 - 0
hxsl/GlslOut.hx

@@ -374,6 +374,8 @@ class GlslOut {
 			decl("vec2 _uintBitsToFloat( ivec2 v ) { return uintBitsToFloat(uvec2(v)); }");
 			decl("vec3 _uintBitsToFloat( ivec3 v ) { return uintBitsToFloat(uvec3(v)); }");
 			decl("vec4 _uintBitsToFloat( ivec4 v ) { return uintBitsToFloat(uvec4(v)); }");
+		case InvLerp:
+			decl("float invLerp(float v, float a, float b) { return clamp((v - a) / (b - a), 0.0, 1.0); }");
 		default:
 		}
 		return GLOBALS[g.getIndex()];

+ 2 - 0
hxsl/HlslOut.hx

@@ -374,6 +374,8 @@ class HlslOut {
 			 }");
 		case AtomicAdd:
 			decl("int atomicAdd( RWStructuredBuffer<int> buf, int index, int data ) { int val; InterlockedAdd(buf[index], data, val); return val; }");
+		case InvLerp: 
+			decl("float invLerp(float v, float a, float b) { return saturate((v - a) / (b - a)); }");
 		case TextureSize:
 			var tt = args[0].t;
 			var tstr = getTexType(tt);