Ver código fonte

- Small opti for volumetric lightmap and indirect lighting

ShiroSmith 7 anos atrás
pai
commit
529042f884

+ 4 - 7
h3d/scene/pbr/Renderer.hx

@@ -266,20 +266,17 @@ class Renderer extends h3d.scene.Renderer {
 			return;
 			return;
 		}
 		}
 
 
-		ctx.extraShaders = new hxsl.ShaderList(pbrProps, null);
+		pbrIndirect.drawIndirectDiffuse = false;
+		pbrIndirect.drawIndirectSpecular = true;
+		ctx.extraShaders = new hxsl.ShaderList(pbrProps, new hxsl.ShaderList(pbrIndirect, null));
 		draw("volumetricLightmap");
 		draw("volumetricLightmap");
 		ctx.extraShaders = null;
 		ctx.extraShaders = null;
 
 
 		pbrProps.isScreen = true;
 		pbrProps.isScreen = true;
 
 
-		pbrIndirect.drawIndirectDiffuse = false;
-		pbrIndirect.drawIndirectSpecular = true;
-		pbrOut.pass.stencil.setFunc(Always);
-		pbrOut.render();
-
 		pbrIndirect.showSky = false;
 		pbrIndirect.showSky = false;
 		pbrIndirect.drawIndirectDiffuse = true;
 		pbrIndirect.drawIndirectDiffuse = true;
-		pbrIndirect.drawIndirectSpecular = false;
+		pbrIndirect.drawIndirectSpecular = true;
 		pbrOut.pass.stencil.setFunc(NotEqual, 0x80, 0x80, 0x80);
 		pbrOut.pass.stencil.setFunc(NotEqual, 0x80, 0x80, 0x80);
 		pbrOut.render();
 		pbrOut.render();
 
 

+ 11 - 7
h3d/shader/pbr/Lighting.hx

@@ -35,16 +35,20 @@ class Indirect extends PropsDefinition {
 					discard;
 					discard;
 			} else {
 			} else {
 
 
+				var diffuse = vec3(0.);
+				var specular = vec3(0.);
+
 				var F0 = pbrSpecularColor;
 				var F0 = pbrSpecularColor;
 				var F = F0 + (max(vec3(1 - roughness), F0) - F0) * exp2( ( -5.55473 * NdV - 6.98316) * NdV );
 				var F = F0 + (max(vec3(1 - roughness), F0) - F0) * exp2( ( -5.55473 * NdV - 6.98316) * NdV );
 
 
-				var diffuse = irrDiffuse.get(normal).rgb * albedo;
-				var envSpec = textureLod(irrSpecular, reflect(-view,normal), roughness * irrSpecularLevels).rgb;
-				var envBRDF = irrLut.get(vec2(roughness, NdV));
-				var specular = envSpec * (F * envBRDF.x + envBRDF.y);
-
-				if( !drawIndirectDiffuse ) diffuse = vec3(0.);
-				if( !drawIndirectSpecular ) specular = vec3(0.);
+				if( drawIndirectDiffuse ){
+					diffuse = irrDiffuse.get(normal).rgb * albedo;
+				}
+				if( drawIndirectSpecular ) {
+					var envSpec = textureLod(irrSpecular, reflect(-view,normal), roughness * irrSpecularLevels).rgb;
+					var envBRDF = irrLut.get(vec2(roughness, NdV));
+					specular = envSpec * (F * envBRDF.x + envBRDF.y);
+				}
 
 
 				var indirect = (diffuse * (1 - metalness) * (1 - F) + specular) * irrPower;
 				var indirect = (diffuse * (1 - metalness) * (1 - F) + specular) * irrPower;
 
 

+ 1 - 1
h3d/shader/pbr/VolumetricLightmap.hx

@@ -153,7 +153,7 @@ class VolumetricLightmap extends hxsl.Shader {
 			var F = F0 + (max(vec3(1 - roughness), F0) - F0) * exp2( ( -5.55473 * NdV - 6.98316) * NdV );
 			var F = F0 + (max(vec3(1 - roughness), F0) - F0) * exp2( ( -5.55473 * NdV - 6.98316) * NdV );
 			var indirect = (irradiance * (1 - metalness) * (1 - F) ) * strength;
 			var indirect = (irradiance * (1 - metalness) * (1 - F) ) * strength;
 
 
-			output.color = vec4(indirect, 1.0);
+			output.color.rgb += indirect;
 		}
 		}
 	}
 	}
 }
 }