فهرست منبع

Fix dispose for spotShadowmap
Update skybox preview

ShiroSmith 5 سال پیش
والد
کامیت
39d1605961
3فایلهای تغییر یافته به همراه25 افزوده شده و 4 حذف شده
  1. 2 1
      h3d/pass/SpotShadowMap.hx
  2. 16 2
      h3d/scene/pbr/Renderer.hx
  3. 7 1
      h3d/shader/pbr/Lighting.hx

+ 2 - 1
h3d/pass/SpotShadowMap.hx

@@ -163,8 +163,9 @@ class SpotShadowMap extends Shadows {
 			return;
 		draw(passes);
 		var texture = sshader.shadowMap;
-		if( staticTexture != null ) staticTexture.dispose();
+		var old = staticTexture;
 		staticTexture = texture.clone();
+		if( old != null ) old.dispose();
 		sshader.shadowMap = staticTexture;
 	}
 }

+ 16 - 2
h3d/scene/pbr/Renderer.hx

@@ -26,6 +26,7 @@ package h3d.scene.pbr;
 @:enum abstract SkyMode(String) {
 	var Hide = "Hide";
 	var Env = "Env";
+	var Specular = "Specular";
 	var Irrad = "Irrad";
 	var Background = "Background";
 }
@@ -318,11 +319,23 @@ class Renderer extends h3d.scene.Renderer {
 			pbrIndirect.skyColor = false;
 			pbrIndirect.skyMap = switch( skyMode ) {
 			case Hide: null;
-			case Env: env.env;
-			case Irrad: env.diffuse;
+			case Env: 
+				pbrIndirect.skyScale = env.scale;
+				pbrIndirect.skyThreshold = env.threshold;
+				pbrIndirect.gammaCorrect = true;
+				env.env;
+			case Specular: 
+				pbrIndirect.skyScale = 1.0;
+				pbrIndirect.gammaCorrect = false;
+				env.specular;
+			case Irrad: 
+				pbrIndirect.skyScale = 1.0;
+				pbrIndirect.gammaCorrect = false;
+				env.diffuse;
 			case Background:
 				pbrIndirect.skyColor = true;
 				pbrIndirect.skyColorValue.setColor(ctx.engine.backgroundColor);
+				pbrIndirect.gammaCorrect = true;
 				null;
 			};
 		case LightProbe:
@@ -577,6 +590,7 @@ class Renderer extends h3d.scene.Renderer {
 							<select field="sky" style="width:20px">
 								<option value="Hide">Hide</option>
 								<option value="Env">Show</option>
+								<option value="Specular">Show Specular</option>
 								<option value="Irrad">Show Irrad</option>
 								<option value="Background">Background Color</option>
 							</select>

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

@@ -19,6 +19,9 @@ class Indirect extends PropsDefinition {
 		@const var drawIndirectDiffuse : Bool;
 		@const var drawIndirectSpecular : Bool;
 		@param var skyMap : SamplerCube;
+		@param var skyThreshold : Float;
+		@param var skyScale : Float;
+		@const var gammaCorrect : Bool;
 		@param var cameraInvViewProj : Mat4;
 		@param var emissivePower : Float;
 		var calculatedUV : Vec2;
@@ -37,8 +40,11 @@ class Indirect extends PropsDefinition {
 						normal = (vec3( uvToScreen(calculatedUV) * 5. /*?*/ , 1. ) * cameraInvViewProj.mat3x4()).normalize();
 						var rotatedNormal = vec3(normal.x * c - normal.y * s, normal.x * s + normal.y * c, normal.z);
 						color = skyMap.get(rotatedNormal).rgb;
+						color.rgb *= mix(1.0, skyScale, (max( max(color.r, max(color.g, color.b)) - skyThreshold, 0) / max(0.001, (1.0 - skyThreshold))));
 					}
-					pixelColor.rgb += (color * color) * irrPower;
+					if( gammaCorrect )
+						color *= color;
+					pixelColor.rgb += color * irrPower;
 				} else
 					discard;
 			} else {