Prechádzať zdrojové kódy

Merge branch 'master' into ctx_globals

Nicolas Cannasse 1 rok pred
rodič
commit
8580ad06b8

+ 1 - 1
h3d/col/Sphere.hx

@@ -7,7 +7,7 @@ class Sphere extends Collider {
 	public var z : Float;
 	public var r : Float;
 
-	public inline function new(x=0., y=0., z=0., r=0.) {
+	public inline function new(x=0., y=0., z=0., r=1.) {
 		load(x, y, z, r);
 	}
 

+ 13 - 5
h3d/impl/DX12Driver.hx

@@ -59,6 +59,7 @@ class ManagedHeapArray {
 
 class DxFrame {
 	public var backBuffer : ResourceData;
+	public var backBufferView : Address;
 	public var depthBuffer : GpuResource;
 	public var allocator : CommandAllocator;
 	public var commandList : CommandList;
@@ -452,9 +453,10 @@ class DX12Driver extends h3d.impl.Driver {
 		curStencilRef = -1;
 		currentIndex = null;
 
+		frame.backBufferView = renderTargetViews.alloc(1);
+		Driver.createRenderTargetView(frame.backBuffer.res, null, frame.backBufferView);
 		setRenderTarget(null);
 
-
 		frame.shaderResourceCache.reset();
 		frame.samplerCache.reset();
 		frame.shaderResourceViews = frame.shaderResourceCache.next();
@@ -488,7 +490,7 @@ class DX12Driver extends h3d.impl.Driver {
 			}
 			// clear backbuffer
 			if( count == 0 )
-				frame.commandList.clearRenderTargetView(tmp.renderTargets[0], clear);
+				frame.commandList.clearRenderTargetView(frame.backBufferView, clear);
 		}
 		if( depth != null || stencil != null )
 			frame.commandList.clearDepthStencilView(tmp.depthStencils[0], depth != null ? (stencil != null ? BOTH : DEPTH) : STENCIL, (depth:Float), stencil);
@@ -673,7 +675,6 @@ class DX12Driver extends h3d.impl.Driver {
 
 		depthEnabled = depthBinding != NotBound;
 
-		var texView = renderTargetViews.alloc(1);
 		var isArr = tex != null && (tex.flags.has(IsArray) || tex.flags.has(Cube));
 		var desc = null;
 		if( layer != 0 || mipLevel != 0 || isArr ) {
@@ -691,8 +692,15 @@ class DX12Driver extends h3d.impl.Driver {
 				desc.planeSlice = 0;
 			}
 		}
-		Driver.createRenderTargetView(tex == null ? frame.backBuffer.res : tex.t.res, desc, texView);
-		tmp.renderTargets[0] = texView;
+		if (tex != null) {
+			var texView = renderTargetViews.alloc(1);
+			Driver.createRenderTargetView(tex.t.res, desc, texView);
+			tmp.renderTargets[0] = texView;
+		}
+		else {
+			tmp.renderTargets[0] = frame.backBufferView;
+		}
+
 		if ( tex != null && !tex.flags.has(WasCleared) ) {
 			tex.flags.set(WasCleared);
 			var clear = tmp.clearColor;

+ 9 - 3
h3d/impl/DirectXDriver.hx

@@ -280,6 +280,8 @@ class DirectXDriver extends h3d.impl.Driver {
 		if( color != null ) {
 			for( i in 0...targetsCount )
 				Driver.clearColor(currentTargets[i], color.r, color.g, color.b, color.a);
+			if (targetsCount == 0)
+				Driver.clearColor(defaultTarget, color.r, color.g, color.b, color.a);
 		}
 		if( currentDepth != null && (depth != null || stencil != null) )
 			Driver.clearDepthStencilView(currentDepth.depthView, depth, stencil);
@@ -839,9 +841,13 @@ class DirectXDriver extends h3d.impl.Driver {
 		if( shaderCache != null ) {
 			var bytes = shaderCache.resolveShaderBinary(code, shaderVersion);
 			if( bytes != null ) {
-				var sh = vertex ? Driver.createVertexShader(bytes) : Driver.createPixelShader(bytes);
-				// shader can't be compiled !
-				if( sh == null )
+				try {
+					var sh = vertex ? Driver.createVertexShader(bytes) : Driver.createPixelShader(bytes);
+					// shader can't be compiled !
+					if( sh == null )
+						return null;
+				}
+				catch( d : Dynamic)
 					return null;
 				return bytes;
 			}

+ 30 - 7
h3d/impl/TextureCache.hx

@@ -38,12 +38,23 @@ class TextureCache {
 		position = 0;
 	}
 
-	function lookupTarget( name, width, height, format, isCube ) {
+	function lookupTarget( name, width, height, format, flags : Array<h3d.mat.Data.TextureFlags> ) {
 		var t = cache[position];
 		// look for a suitable candidate
 		for( i in position+1...cache.length ) {
 			var t2 = cache[i];
-			if( t2 != null && !t2.isDisposed() && t2.width == width && t2.height == height && t2.format == format && isCube == t2.flags.has(Cube) ) {
+			if( t2 != null && !t2.isDisposed() && t2.width == width && t2.height == height && t2.format == format ) {
+				if ( flags != null ) {
+					var fitFlags = true;
+					for ( f in flags ) {
+						if ( !t2.flags.has(f) ) {
+							fitFlags = false;
+							break;
+						}
+					}
+					if ( !fitFlags )
+						continue;
+				}
 				// swap
 				cache[position] = t2;
 				cache[i] = t;
@@ -55,8 +66,9 @@ class TextureCache {
 			t.dispose();
 			t = null;
 		}
-		var flags : Array<h3d.mat.Data.TextureFlags> = [Target];
-		if( isCube ) flags.push(Cube);
+		if ( flags == null ) flags = [];
+		if ( !flags.contains(Target) )
+			flags.push(Target);
 		var newt = new h3d.mat.Texture(width, height, flags, format);
 		// make the texture disposable if we're out of memory
 		newt.realloc = function() {};
@@ -67,11 +79,22 @@ class TextureCache {
 		return newt;
 	}
 
-	public function allocTarget( name : String, width : Int, height : Int, defaultDepth=true, ?format:hxd.PixelFormat, isCube = false ) {
+	public function allocTarget( name : String, width : Int, height : Int, defaultDepth=true, ?format:hxd.PixelFormat, flags : Array<h3d.mat.Data.TextureFlags> = null ) {
 		var t = cache[position];
 		if( format == null ) format = defaultFormat;
-		if( t == null || t.isDisposed() || t.width != width || t.height != height || t.format != format || isCube != t.flags.has(Cube) )
-			t = lookupTarget(name,width,height,format,isCube);
+		var alloc = false;
+		if( t == null || t.isDisposed() || t.width != width || t.height != height || t.format != format )
+			alloc = true;
+		if ( !alloc && flags != null ) {
+			for ( f in flags ) {
+				if ( !t.flags.has(f) ) {
+					alloc = true;
+					break;
+				}
+			}
+		}
+		if ( alloc )
+			t = lookupTarget(name,width,height,format,flags);
 		t.depthBuffer = defaultDepth ? defaultDepthBuffer : null;
 		t.setName(name);
 		position++;

+ 1 - 1
h3d/pass/Blur.hx

@@ -135,7 +135,7 @@ class Blur extends ScreenFx<h3d.shader.Blur> {
 
 		var isCube = src.flags.has(Cube);
 		var faceCount = isCube ? 6 : 1;
-		var tmp = ctx.textures.allocTarget(src.name+"BlurTmp", src.width, src.height, false, src.format, isCube);
+		var tmp = ctx.textures.allocTarget(src.name+"BlurTmp", src.width, src.height, false, src.format, isCube ? [Cube] : null);
 
 		shader.Quality = values.length;
 		shader.values = values;

+ 2 - 2
h3d/pass/CubeShadowMap.hx

@@ -162,7 +162,7 @@ class CubeShadowMap extends Shadows {
 			return;
 		}
 
-		var texture = ctx.computingStatic ? createStaticTexture() : ctx.textures.allocTarget("pointShadowMap", size, size, false, format, true);
+		var texture = ctx.computingStatic ? createStaticTexture() : ctx.textures.allocTarget("pointShadowMap", size, size, false, format, [Cube]);
 		if( depth == null || depth.width != texture.width || depth.height != texture.height || depth.isDisposed() ) {
 			if( depth != null ) depth.dispose();
 			depth = new h3d.mat.Texture(texture.width, texture.height, Depth24Stencil8);
@@ -221,7 +221,7 @@ class CubeShadowMap extends Shadows {
 		var validBakedTexture = (staticTexture != null && staticTexture.width == dynamicTex.width);
 		var merge : h3d.mat.Texture = null;
 		if( mode == Mixed && !ctx.computingStatic && validBakedTexture)
-			merge = ctx.textures.allocTarget("mergedPointShadowMap", size, size, false, format, true);
+			merge = ctx.textures.allocTarget("mergedPointShadowMap", size, size, false, format, [Cube]);
 
 		if( mode == Mixed && !ctx.computingStatic && merge != null ) {
 			for( i in 0 ... 6 ) {

+ 6 - 5
h3d/pass/DirShadowMap.hx

@@ -261,15 +261,16 @@ class DirShadowMap extends Shadows {
 	}
 
 	function processShadowMap( passes, tex, ?sort) {
-
 		var prevViewProj = @:privateAccess ctx.cameraViewProj;
 		@:privateAccess ctx.cameraViewProj = getShadowProj();
-
-		if ( tex.isDepth() )
+		if ( tex.isDepth() ) {
 			ctx.engine.pushDepth(tex);
-		else
+			ctx.engine.clear(null, 1.0);
+		}
+		else {
 			ctx.engine.pushTarget(tex);
-		ctx.engine.clear(0xFFFFFF, 1.0);
+			ctx.engine.clear(0xFFFFFF);
+		}
 		super.draw(passes, sort);
 
 		var doBlur = blur.radius > 0 && (mode != Mixed || !ctx.computingStatic);

+ 1 - 1
h3d/pass/ShaderManager.hx

@@ -16,7 +16,7 @@ class ShaderManager {
 		currentOutput.s = shaderCache.getLinkShader(output);
 	}
 
-	public function compileShaders( globals : hxsl.Globals, shaders : hxsl.ShaderList, mode : hxsl.Linker.LinkMode = Default ) {
+	public function compileShaders( globals : hxsl.Globals, shaders : hxsl.ShaderList, mode : hxsl.RuntimeShader.LinkMode = Default ) {
 		globals.resetChannels();
 		for( s in shaders ) s.updateConstants(globals);
 		currentOutput.next = shaders;

+ 1 - 1
h3d/prim/Polygon.hx

@@ -110,7 +110,7 @@ class Polygon extends MeshPrimitive {
 		}
 	}
 
-	public function translate( dx, dy, dz ) {
+	public function translate( dx : Float, dy : Float, dz : Float ) {
 		translatedX += dx;
 		translatedY += dy;
 		translatedZ += dz;

+ 6 - 0
h3d/shader/Checker.hx

@@ -9,6 +9,12 @@ class Checker extends hxsl.Shader {
 		@param var height : Float;
 
 		var calculatedUV : Vec2;
+
+		@input var input : { var uv : Vec2; }
+		function vertex() {
+			calculatedUV = input.uv;
+		}
+
 		function fragment() {
 			if ( ((calculatedUV.fract().x - 0.5) * (calculatedUV.fract().y - 0.5)) > 0.0 ) {
 				pixelColor.rgb = vec3(1.0);

+ 40 - 24
hxd/fmt/hmd/Library.hx

@@ -14,6 +14,21 @@ private class FormatMap {
 	}
 }
 
+#if hide
+private class ContextShared extends hrt.prefab.ContextShared {
+	var customLoadTexture : String -> h3d.mat.Texture;
+
+	public function new(loadTexture : String -> h3d.mat.Texture, ?res : hxd.res.Resource) {
+		super(res);
+		this.customLoadTexture = loadTexture;
+	}
+
+	override function loadTexture(path:String, async:Bool = false):h3d.mat.Texture {
+			return customLoadTexture(path);
+	}
+}
+#end
+
 class GeometryBuffer {
 	public var vertexes : haxe.ds.Vector<hxd.impl.Float32>;
 	public var indexes : haxe.ds.Vector<Int>;
@@ -278,7 +293,7 @@ class Library {
 		#if hide
 		if( (props:Dynamic).__ref != null ) {
 			try {
-				if ( setupMaterialLibrary(mat, hxd.res.Loader.currentInstance.load((props:Dynamic).__ref).toPrefab(), (props:Dynamic).name) )
+				if ( setupMaterialLibrary(loadTexture, mat, hxd.res.Loader.currentInstance.load((props:Dynamic).__ref).toPrefab(), (props:Dynamic).name) )
 					return mat;
 			} catch( e : Dynamic ) {
 			}
@@ -740,29 +755,30 @@ class Library {
 	}
 
 	#if hide
-	public dynamic static function setupMaterialLibrary( mat : h3d.mat.Material, lib : hrt.prefab.Resource, name : String ) {
-		var m  = lib.load().getOpt(hrt.prefab.Material,name);
-		if ( m == null )
-			return false;
-		@:privateAccess m.update(mat, m.renderProps(),
-		function loadTexture ( path : String ) {
-			return hxd.res.Loader.currentInstance.load(path).toTexture();
-		});
-		for ( c in m.children ) {
-			var shader = Std.downcast(c, hrt.prefab.Shader);
-			if ( shader == null )
-				continue;
-			#if prefab2
-			var s = shader.make().shader;
-			#else
-			shader.clone();
-			var ctx = new hrt.prefab.Context();
-			var s = shader.makeShader(ctx);
-			#end
-			@:privateAccess shader.applyShader(null, mat, s);
-		}
-		return true;
-	}
+	static var materialContainer : h3d.scene.Mesh;
+    public dynamic static function setupMaterialLibrary( loadTexture : String -> h3d.mat.Texture, mat : h3d.mat.Material, lib : hrt.prefab.Resource, name : String ) {
+        var m  = lib.load().getOpt(hrt.prefab.Material,name);
+        if ( m == null )
+            return false;
+
+		if (materialContainer == null)
+			materialContainer = new h3d.scene.Mesh(null, mat, null);
+
+        var ctx = new hrt.prefab.Context();
+		ctx.shared = new ContextShared(loadTexture, null);
+
+        materialContainer.material = mat;
+        ctx.local3d = materialContainer;
+        m.make(ctx);
+
+        // Ensure there is no leak with this
+		materialContainer.material = null;
+
+		while (materialContainer.numChildren > 0)
+			@:privateAccess materialContainer.children[materialContainer.numChildren - 1].remove();
+
+        return true;
+    }
 	#end
 
 }

+ 2 - 0
hxd/net/Socket.hx

@@ -41,6 +41,8 @@ class Socket {
 	public var out(default, null) : SocketOutput;
 	public var input(default, null) : SocketInput;
 	public var timeout(default, set) : Null<Float>;
+	
+	public static inline var ALLOW_BIND = #if (hl || (nodejs && hxnodejs)) true #else false #end;
 
 	public function new() {
 		out = new SocketOutput();

+ 0 - 1
hxsl/Cache.hx

@@ -1,7 +1,6 @@
 package hxsl;
 using hxsl.Ast;
 import hxsl.RuntimeShader;
-import hxsl.Linker.LinkMode;
 
 class BatchInstanceParams {
 

+ 1 - 1
hxsl/CacheFile.hx

@@ -271,7 +271,7 @@ class CacheFile extends Cache {
 
 			for( r in runtimes ) {
 				var shaderList = null;
-				var mode : hxsl.Linker.LinkMode = Default;
+				var mode : RuntimeShader.LinkMode = Default;
 				r.inst.reverse();
 				for( i in r.inst ) {
 					var s = Type.createEmptyInstance(hxsl.Shader);

+ 5 - 5
hxsl/CacheFileBuilder.hx

@@ -131,7 +131,7 @@ class CacheFileBuilder {
 			}
 			var out = new HlslOut();
 			var code = out.run(rd.data);
-			var bytes = dx.Driver.compileShader(code, "", "main", (rd.vertex?"vs_":"ps_") + dxShaderVersion, OptimizationLevel3);
+			var bytes = dx.Driver.compileShader(code, "", "main", ((rd.kind == Vertex)?"vs_":"ps_") + dxShaderVersion, OptimizationLevel3);
 			return { code : code, bytes : bytes };
 			#else
 			throw "DirectX compilation requires -lib hldx without -D dx12";
@@ -151,7 +151,7 @@ class CacheFileBuilder {
 			var tmpSrc = tmpFile + ".pssl";
 			var tmpOut = tmpFile + ".sb";
 			sys.io.File.saveContent(tmpSrc, code);
-			var args = ["-profile", rd.vertex ? "sce_vs_vs_orbis" : "sce_ps_orbis", "-o", tmpOut, tmpSrc];
+			var args = ["-profile", (rd.kind == Vertex) ? "sce_vs_vs_orbis" : "sce_ps_orbis", "-o", tmpOut, tmpSrc];
 			var p = new sys.io.Process("orbis-wave-psslc.exe", args);
 			var error = p.stderr.readAll().toString();
 			var ecode = p.exitCode();
@@ -196,12 +196,12 @@ class CacheFileBuilder {
 			var tmpSrc = tmpFile + ".hlsl";
 			var tmpOut = tmpFile + ".sb";
 			var sign = @:privateAccess dx12Driver.computeRootSignature(r);
-			out.baseRegister = rd.vertex ? 0 : sign.fragmentRegStart;
+			out.baseRegister = (rd.kind == Vertex) ? 0 : sign.fragmentRegStart;
 			var code = out.run(rd.data);
-			var serializeRootSignature = @:privateAccess dx12Driver.stringifyRootSignature(sign.sign, "ROOT_SIGNATURE", sign.params);
+			var serializeRootSignature = @:privateAccess dx12Driver.stringifyRootSignature(sign.sign, "ROOT_SIGNATURE", sign.params, sign.paramsCount);
 			code = serializeRootSignature + code;
 			sys.io.File.saveContent(tmpSrc, code);
-			var args = ["-rootsig-define", "ROOT_SIGNATURE", "-T", (rd.vertex ? "vs_" : "ps_") + dxcShaderVersion,"-O3","-Fo", tmpOut, tmpSrc];
+			var args = ["-rootsig-define", "ROOT_SIGNATURE", "-T", ( (rd.kind == Vertex) ? "vs_" : "ps_") + dxcShaderVersion,"-O3","-Fo", tmpOut, tmpSrc];
 			var p = new sys.io.Process(Sys.getEnv("GXDKLatest")+ "bin\\Scarlett\\dxc.exe", args);
 			var error = p.stderr.readAll().toString();
 			var ecode = p.exitCode();

+ 36 - 24
hxsl/Linker.hx

@@ -1,12 +1,6 @@
 package hxsl;
 using hxsl.Ast;
 
-enum LinkMode {
-	Default;
-	Batch;
-	Compute;
-}
-
 private class AllocatedVar {
 	public var id : Int;
 	public var v : TVar;
@@ -28,8 +22,10 @@ private class ShaderInfos {
 	public var body : TExpr;
 	public var usedFunctions : Array<TFunction>;
 	public var deps : Map<ShaderInfos, Bool>;
-	public var read : Map<Int,AllocatedVar>;
-	public var write : Map<Int,AllocatedVar>;
+	public var readMap : Map<Int,AllocatedVar>;
+	public var readVars : Array<AllocatedVar>;
+	public var writeMap : Map<Int,AllocatedVar>;
+	public var writeVars : Array<AllocatedVar>;
 	public var processed : Map<Int, Bool>;
 	public var vertex : Null<Bool>;
 	public var onStack : Bool;
@@ -42,8 +38,10 @@ private class ShaderInfos {
 		this.vertex = v;
 		processed = new Map();
 		usedFunctions = [];
-		read = new Map();
-		write = new Map();
+		readMap = new Map();
+		readVars = [];
+		writeMap = new Map();
+		writeVars = [];
 	}
 }
 
@@ -56,7 +54,7 @@ class Linker {
 	var varIdMap : Map<Int,Int>;
 	var locals : Map<Int,Bool>;
 	var curInstance : Int;
-	var mode : LinkMode;
+	var mode : hxsl.RuntimeShader.LinkMode;
 	var isBatchShader : Bool;
 	var debugDepth = 0;
 
@@ -193,9 +191,12 @@ class Linker {
 		switch( e.e ) {
 		case TVar(v) if( !locals.exists(v.id) ):
 			var v = allocVar(v, e.p);
-			if( curShader != null && !curShader.write.exists(v.id) ) {
+			if( curShader != null && !curShader.writeMap.exists(v.id) ) {
 				debug(curShader.name + " read " + v.path);
-				curShader.read.set(v.id, v);
+				if( !curShader.readMap.exists(v.id) ) {
+					curShader.readMap.set(v.id, v);
+					curShader.readVars.push(v);
+				}
 				// if we read a varying, force into fragment
 				if( curShader.vertex == null && v.v.kind == Var ) {
 					debug("Force " + curShader.name+" into fragment (use varying)");
@@ -208,9 +209,10 @@ class Linker {
 			case [OpAssign, TVar(v)] if( !locals.exists(v.id) ):
 				var e2 = mapExprVar(e2);
 				var v = allocVar(v, e1.p);
-				if( curShader != null ) {
+				if( curShader != null && !curShader.writeMap.exists(v.id) ) {
 					debug(curShader.name + " write " + v.path);
-					curShader.write.set(v.id, v);
+					curShader.writeMap.set(v.id, v);
+					curShader.writeVars.push(v);
 				}
 				// don't read the var
 				return { e : TBinop(op, { e : TVar(v.v), t : v.v.type, p : e.p }, e2), t : e.t, p : e.p };
@@ -220,10 +222,11 @@ class Linker {
 				var e2 = mapExprVar(e2);
 
 				var v = allocVar(v, e1.p);
-				if( curShader != null ) {
+				if( curShader != null && !curShader.writeMap.exists(v.id) ) {
 					// TODO : mark as partial write if SWIZ
 					debug(curShader.name + " write " + v.path);
-					curShader.write.set(v.id, v);
+					curShader.writeMap.set(v.id, v);
+					curShader.writeVars.push(v);
 				}
 				return { e : TBinop(op, e1, e2), t : e.t, p : e.p };
 			default:
@@ -267,7 +270,7 @@ class Linker {
 				continue;
 			} else if( !found )
 				continue;
-			if( !parent.write.exists(v.id) )
+			if( !parent.writeMap.exists(v.id) )
 				continue;
 			if( s.vertex ) {
 				if( parent.vertex == false )
@@ -280,7 +283,7 @@ class Linker {
 			debugDepth++;
 			initDependencies(parent);
 			debugDepth--;
-			if( !parent.read.exists(v.id) )
+			if( !parent.readMap.exists(v.id) )
 				return;
 		}
 		if( v.v.kind == Var )
@@ -291,8 +294,8 @@ class Linker {
 		if( s.deps != null )
 			return;
 		s.deps = new Map();
-		for( r in s.read )
-			buildDependency(s, r, s.write.exists(r.id));
+		for( r in s.readVars )
+			buildDependency(s, r, s.writeMap.exists(r.id));
 		// propagate fragment flag
 		if( s.vertex == null )
 			for( d in s.deps.keys() )
@@ -412,6 +415,15 @@ class Linker {
 		}
 		shaders.sort(sortByPriorityDesc);
 
+		var uid = 0;
+		for( s in shaders )
+			s.uid = uid++;
+
+		#if shader_debug_dump
+		for( s in shaders )
+			debug("Found shader "+s.name+":"+s.uid);
+		#end
+
 		// build dependency tree
 		var entry = new ShaderInfos("<entry>", false);
 		entry.deps = new Map();
@@ -430,7 +442,7 @@ class Linker {
 		for( s in shaders ) {
 			if( s.vertex != null ) continue;
 			var onlyParams = true;
-			for( r in s.read )
+			for( r in s.readVars )
 				if( r.v.kind != Param ) {
 					onlyParams = false;
 					break;
@@ -470,9 +482,9 @@ class Linker {
 				outVars.push(v.v);
 		}
 		for( s in v.concat(f) ) {
-			for( v in s.read )
+			for( v in s.readVars )
 				addVar(v);
-			for( v in s.write )
+			for( v in s.writeVars )
 				addVar(v);
 		}
 		// cleanup unused structure vars

+ 7 - 1
hxsl/RuntimeShader.hx

@@ -1,5 +1,11 @@
 package hxsl;
 
+enum LinkMode {
+	Default;
+	Batch;
+	Compute;
+}
+
 class AllocParam {
 	public var name : String;
 	public var pos : Int;
@@ -86,7 +92,7 @@ class RuntimeShader {
 		Several shaders with the different specification might still get the same resulting signature.
 	**/
 	public var signature : String;
-	public var mode : hxsl.Linker.LinkMode;
+	public var mode : LinkMode;
 	public var spec : { instances : Array<ShaderInstanceDesc>, signature : String };
 
 	public function new() {

+ 1 - 1
samples/Helpers.hx

@@ -117,7 +117,7 @@ class PointLightHelper extends h3d.scene.Mesh {
 		prim.addNormals();
 		prim.addUVs();
 		super( prim, light );
-		material.color = light.color;
+		material.color = light.color.toVector4();
 		material.mainPass.wireframe = true;
 	}
 }

+ 3 - 3
samples/Interactive.hx

@@ -66,7 +66,7 @@ class Interactive extends SampleApp {
 
 			m.material.shadows = true;
 			var c = 0.3 + rnd.rand() * 0.3;
-			var color = new h3d.Vector(c, c * 0.6, c * 0.6);
+			var color = new h3d.Vector4(c, c * 0.6, c * 0.6);
 			m.material.color.load(color);
 
 			var interact = new h3d.scene.Interactive(m.getCollider(), s3d);
@@ -89,7 +89,7 @@ class Interactive extends SampleApp {
 
 			m.material.shadows = true;
 			var c = 0.3 + rnd.rand() * 0.3;
-			var color = new h3d.Vector(c, c * 0.6, c * 0.6);
+			var color = new h3d.Vector4(c, c * 0.6, c * 0.6);
 			m.material.color.load(color);
 
 			var p1 = new h3d.col.Point(0, 0, cheight);
@@ -113,7 +113,7 @@ class Interactive extends SampleApp {
 
 			m.material.shadows = true;
 			var c = 0.3 + rnd.rand() * 0.3;
-			var color = new h3d.Vector(c, c * 0.6, c * 0.6);
+			var color = new h3d.Vector4(c, c * 0.6, c * 0.6);
 			m.material.color.load(color);
 
 			var col = m.getBounds();

+ 4 - 4
samples/Lights.hx

@@ -46,7 +46,7 @@ class Lights extends SampleApp {
 		for( i in 0...50 ) {
 			var m = new h3d.scene.Mesh(box, s3d);
 			m.material.color.set(Math.random(), Math.random(), Math.random());
-			m.material.color.normalize();
+			m.material.color.normalize3();
 			m.scale(1 + Math.random() * 10);
 			m.z = m.scaleX * 0.5;
 			m.setRotation(0,0,Math.random() * Math.PI * 2);
@@ -65,7 +65,7 @@ class Lights extends SampleApp {
 		for( i in 0...20 ) {
 			var m = new h3d.scene.Mesh(sp, s3d);
 			m.material.color.set(Math.random(), Math.random(), Math.random());
-			m.material.color.normalize();
+			m.material.color.normalize3();
 			m.scale(0.5 + Math.random() * 4);
 			m.z = 2 + Math.random() * 5;
 			var cx = (Math.random() - 0.5) * 20;
@@ -80,14 +80,14 @@ class Lights extends SampleApp {
 		var pt = new h3d.scene.pbr.PointLight(s3d);
 		pt.setPosition(0,0,15);
 		pt.range = 40;
-		pt.color.scale3(20);
+		pt.color.scale(20);
 
 		var sp = new h3d.scene.pbr.SpotLight(s3d);
 		sp.setPosition(-30,-30,30);
 		sp.setDirection(new h3d.Vector(1,2,-5));
 		sp.range = 70;
 		sp.angle = 70;
-		sp.color.scale3(10);
+		sp.color.scale(10);
 
 		lights = [
 			new h3d.scene.pbr.DirLight(new h3d.Vector(1,2,-5), s3d),

+ 1 - 1
samples/MeshBatch.hx

@@ -71,7 +71,7 @@ class MeshBatch extends hxd.App {
 			batch.y = m.y;
 			batch.setScale(m.scale);
 			batch.setRotation(0,0,m.rot);
-			shader.color.load(m.color);
+			shader.color.load(m.color.toVec3());
 			batch.emitInstance();
 		}
 	}

+ 1 - 1
samples/Pbr.hx

@@ -151,7 +151,7 @@ class Pbr extends SampleApp {
 
 		if( grid == null ) return;
 
-		var color = new h3d.Vector(1, 0, 0);
+		var color = new h3d.Vector4(1, 0, 0, 1);
 		var m = new h3d.Matrix();
 		m.identity();
 		m.colorSaturate(saturation - 1);

+ 6 - 6
samples/ShaderAdvanced.hx

@@ -86,7 +86,7 @@ class ShaderAdvanced extends hxd.App {
 			try {
 				var t = new h3d.mat.Texture(1,1,[Target],fmt);
 				d.setRenderTarget(t);
-				d.clear(new h3d.Vector(1,0.5,0.25,0.125));
+				d.clear(new h3d.Vector4(1,0.5,0.25,0.125));
 				d.setRenderTarget(null);
 				var pix = t.capturePixels();
 				var hex = pix.bytes.toHex();
@@ -95,7 +95,7 @@ class ShaderAdvanced extends hxd.App {
 					throw hex+" should be "+values.get(fmt);
 
 				d.setRenderTarget(t);
-				d.clear(new h3d.Vector(0,0,0,0));
+				d.clear(new h3d.Vector4(0,0,0,0));
 				d.setRenderTarget(null);
 
 				t.uploadPixels(pix);
@@ -111,7 +111,7 @@ class ShaderAdvanced extends hxd.App {
 		// uniform buffer
 		var bmp = new h2d.Bitmap(h2d.Tile.fromColor(0xFF0000,128,128),s2d);
 		var ubuffer = bmp.addShader(new TestUniformBuffer());
-		ubuffer.colorMatrix = new h3d.Buffer(4,4,[UniformBuffer,Dynamic]);
+		ubuffer.colorMatrix = new h3d.Buffer(4,hxd.BufferFormat.VEC4_DATA,[UniformBuffer,Dynamic]);
 		var hue : Float = 0.;
 		updates.push(function(dt) {
 			hue += dt * 6;
@@ -122,7 +122,7 @@ class ShaderAdvanced extends hxd.App {
 			var buf = new hxd.FloatBuffer();
 			for( v in m.getFloats() )
 				buf.push(v);
-			ubuffer.colorMatrix.uploadVector(buf, 0, 4);
+			ubuffer.colorMatrix.uploadFloats(buf, 0, 4);
 		});
 
 		// texture array
@@ -155,8 +155,8 @@ class ShaderAdvanced extends hxd.App {
 			buf.push(i * 0.4);
 			buf.push(i * 0.2);
 		}
-		var instanceBuffer = h3d.Buffer.ofFloats(buf,2);
-		prim.addBuffer("offset",instanceBuffer);
+		var instanceBuffer = h3d.Buffer.ofFloats(buf,hxd.BufferFormat.make([{name : "offset",type:DVec2}]));
+		cube.addBuffer(instanceBuffer);
 
 		var m = new h3d.scene.Mesh(prim, s3d);
 		m.material.mainPass.addShader(new InstancedOffsetShader());