2
0
Эх сурвалжийг харах

- Texture : add noiseTexture allocation
- BaseMesh : reset depth in init__fragment()

bstouls 10 жил өмнө
parent
commit
85f9209e8e

+ 23 - 0
h3d/mat/Texture.hx

@@ -236,4 +236,27 @@ class Texture {
 		return t;
 	}
 
+	static var noiseTextures = new Map<Int,h3d.mat.Texture>();
+
+	public static function genNoise(size) {
+		var t = noiseTextures.get(size);
+		if( t != null && !t.isDisposed() )
+			return t;
+		var t = new h3d.mat.Texture(size, size, [NoAlloc]);
+		t.realloc = allocNoise.bind(t,size);
+		noiseTextures.set(size, t);
+		return t;
+	}
+
+	static function allocNoise( t : h3d.mat.Texture, size : Int ) {
+		var b = new hxd.BitmapData(size, size);
+		for( x in 0...size )
+			for( y in 0...size ) {
+				var n = Std.random(256);
+				b.setPixel(x, y, 0xFF000000 | n | (n << 8) | (n << 16));
+			}
+		t.uploadBitmap(b);
+		b.dispose();
+	}
+
 }

+ 1 - 1
h3d/pass/Normal.hx

@@ -17,7 +17,7 @@ class Normal extends Default {
 	override function draw( passes ) {
 		var texture = tcache.allocTarget("normalMal", ctx, ctx.engine.width, ctx.engine.height);
 		ctx.engine.setTarget(texture);
-		ctx.engine.clear(0, 1);
+		ctx.engine.clear(0x808080, 1);
 		passes = super.draw(passes);
 		ctx.setGlobalID(normalMapId, texture);
 		return passes;

+ 1 - 13
h3d/pass/ScalableAO.hx

@@ -81,22 +81,10 @@ private class SAOShader extends h3d.shader.ScreenShader {
 		numSpiralTurns = 7;
 		bias = 0.01;
 		noiseScale.set(10, 10);
-		noiseTexture = getNoise(128);
+		noiseTexture = h3d.mat.Texture.genNoise(128);
 		noiseTexture.wrap = Repeat;
 	}
 
-	public function getNoise(size) {
-		var b = new hxd.BitmapData(size, size);
-		for( x in 0...size )
-			for( y in 0...size ) {
-				var n = Std.random(256);
-				b.setPixel(x, y, 0xFF000000 | n | (n << 8) | (n << 16));
-			}
-		var t = h3d.mat.Texture.fromBitmap(b);
-		b.dispose();
-		return t;
-	}
-
 }
 
 class ScalableAO extends h3d.pass.ScreenFx<SAOShader> {

+ 1 - 0
h3d/shader/BaseMesh.hx

@@ -66,6 +66,7 @@ class BaseMesh extends hxsl.Shader {
 		}
 
 		function __init__fragment() {
+			depth = projectedPosition.z / projectedPosition.w; // in case it's used in vertex : we don't want to interpolate in screen space
 			transformedNormal = transformedNormal.normalize();
 			specPower = specularPower;
 			specColor = specularColor * specularAmount;