Explorar o código

Support of PbrMaterialSetup gloss() method. Remove createAtlasShader.

clementlandrin hai 3 semanas
pai
achega
131ebf99e4

+ 5 - 1
hrt/prefab/l3d/modellibrary/AtlasShader.hx

@@ -12,6 +12,7 @@ class AtlasShader extends hxsl.Shader {
 		@const var hasNormal : Bool;
 		@const var hasPbr : Bool;
 		@const var AUTO_LOD : Bool;
+		@const var GLOSS : Bool = true;
 
 		@param var texture : Sampler2D;
 		@param var normalMap : Sampler2D;
@@ -42,7 +43,10 @@ class AtlasShader extends hxsl.Shader {
 
 		function unpackPBR(v : Vec4) : Vec4 {
 			metalness = v.r;
-			roughness = 1 - v.g * v.g;
+			if ( GLOSS )
+				roughness = 1 - v.g * v.g;
+			else
+				roughness = v.g;
 			occlusion = v.b;
 			// no emissive for now
 		}

+ 3 - 1
hrt/prefab/l3d/modellibrary/ModelLibrary.hx

@@ -772,7 +772,9 @@ class ModelLibrary extends Prefab {
 			cache.geomBounds = [for( g in @:privateAccess cache.hmdPrim.lib.header.geometries ) g.bounds];
 		@:privateAccess cache.hmdPrim.curMaterial = -1;
 		if ( cache.shader == null ) {
-			cache.shader = cast(h3d.mat.MaterialSetup.current, h3d.mat.PbrMaterialSetup).createAtlasShader();
+			var pbrMaterialSetup = cast(h3d.mat.MaterialSetup.current, h3d.mat.PbrMaterialSetup);
+			cache.shader = new AtlasShader();
+			cache.shader.GLOSS = pbrMaterialSetup.gloss();
 			cache.shader.mipStart = mipStart;
 			cache.shader.mipEnd = mipEnd;
 			cache.shader.mipPower = mipPower;

+ 1 - 0
hrt/prefab/terrain/Tile.hx

@@ -67,6 +67,7 @@ class Tile extends h3d.scene.Mesh {
 		tileX = x;
 		tileY = y;
 		shader = new hrt.shader.Terrain();
+		shader.GLOSS = cast(h3d.mat.MaterialSetup.current, h3d.mat.PbrMaterialSetup).gloss();
 		material.mainPass.addShader(shader);
 		material.mainPass.culling = Back;
 		material.staticShadows = true;

+ 5 - 1
hrt/shader/Terrain.hx

@@ -4,6 +4,7 @@ class Terrain extends hxsl.Shader {
 
 	static var SRC = {
 
+		@const var GLOSS : Bool = true;
 		@const var SHOW_GRID : Bool;
 		@const var SURFACE_COUNT : Int;
 		@const var CHECKER : Bool;
@@ -227,7 +228,10 @@ class Terrain extends hxsl.Shader {
 				// Output
 				transformedNormal = normalize(normal * TBN);
 				pixelColor = vec4(albedo, 1.0);
-				roughness = 1 - pbr.g * pbr.g;
+				if ( GLOSS )
+					roughness = 1 - pbr.g * pbr.g;
+				else
+					roughness = pbr.g;
 				metalness = pbr.r;
 				occlusion = pbr.b;
 				emissive = 0;