Explorar o código

Add uv mapping to normalMap to fix bug where it used alone and calculatedUV is not setup properly.

borisrp hai 1 mes
pai
achega
92570abbca
Modificáronse 1 ficheiros con 17 adicións e 15 borrados
  1. 17 15
      h3d/shader/NormalMap.hx

+ 17 - 15
h3d/shader/NormalMap.hx

@@ -2,32 +2,34 @@ package h3d.shader;
 
 class NormalMap extends hxsl.Shader {
 
-    static var SRC = {
+	static var SRC = {
 
 		@global var camera : {
 			var position : Vec3;
 			@var var dir : Vec3;
 		};
 
-        @global var global : {
-            @perObject var modelView : Mat4;
-        };
+		@global var global : {
+			@perObject var modelView : Mat4;
+		};
 
-        @input var input : {
-            var normal : Vec3;
+		@input var input : {
+			var uv : Vec2;
+			var normal : Vec3;
 			var tangent : Vec3;
-        };
+		};
 
-        @param var texture : Sampler2D;
+		@param var texture : Sampler2D;
 
-        var calculatedUV : Vec2;
+		var calculatedUV : Vec2;
 		var transformedPosition : Vec3;
-        var transformedNormal : Vec3;
+		var transformedNormal : Vec3;
 
 		@var var transformedTangent : Vec4;
 
 		function __init__vertex() {
 			transformedTangent = vec4(input.tangent * global.modelView.mat3(),input.tangent.dot(input.tangent) > 0.5 ? 1. : -1.);
+			calculatedUV = input.uv;
 		}
 
 		function fragment() {
@@ -38,11 +40,11 @@ class NormalMap extends hxsl.Shader {
 			transformedNormal = (nf.x * tanX + nf.y * tanY + nf.z * n).normalize();
 		}
 
-     };
+	 };
 
-    public function new(?texture) {
-        super();
-        this.texture = texture;
-    }
+	public function new(?texture) {
+		super();
+		this.texture = texture;
+	}
 
 }