Explorar o código

Decal shader computes calculatedUV in init fragment for later use by other shaders.

clementlandrin %!s(int64=2) %!d(string=hai) anos
pai
achega
a75a2fdc9b
Modificáronse 2 ficheiros con 16 adicións e 16 borrados
  1. 5 1
      h3d/shader/VolumeDecal.hx
  2. 11 15
      h3d/shader/pbr/VolumeDecal.hx

+ 5 - 1
h3d/shader/VolumeDecal.hx

@@ -20,7 +20,7 @@ class VolumeDecal extends hxsl.Shader {
 			transformedTangent = vec4((tangent * global.modelView.mat3()).normalize(),1.);
 		}
 
-		function fragment() {
+		function __init__fragment() {
 			var matrix = camera.inverseViewProj * global.modelViewInverse;
 			var screenPos = projectedPosition.xy / projectedPosition.w;
 			var ruv = vec4(
@@ -32,6 +32,10 @@ class VolumeDecal extends hxsl.Shader {
 			var ppos = ruv * camera.inverseViewProj;
 			pixelTransformedPosition = ppos.xyz / ppos.w;
 			calculatedUV = scale * (wpos.xy / wpos.w);
+		}
+
+		function fragment() {
+			
 			if( isCentered ) calculatedUV += 0.5;
 			if( min(min(calculatedUV.x, calculatedUV.y), min(1 - calculatedUV.x, 1 - calculatedUV.y)) < 0 )
 				discard;

+ 11 - 15
h3d/shader/pbr/VolumeDecal.hx

@@ -82,10 +82,6 @@ class DecalOverlay extends BaseDecal {
 
 
 		function __init__fragment() {
-		}
-
-		function fragment() {
-
 			{
 				var matrix = camera.inverseViewProj * global.modelViewInverse;
 				var screenPos = projectedPosition.xy / projectedPosition.w;
@@ -105,8 +101,9 @@ class DecalOverlay extends BaseDecal {
 				if(	outsideBounds(localPos) )
 					discard;
 			}
+		}
 
-
+		function fragment() {
 			if(USE_NORMAL_FADE) {
 				var worldNormal = getWorldNormal();
 				normalFade(worldNormal);
@@ -162,14 +159,6 @@ class DecalPBR extends BaseDecal {
 		}
 
 		function __init__fragment() {
-			output.albedoStrength = USE_ALBEDO ? albedoStrength * pixelColor.a * fadeFactor : 0.0;
-			output.normalStrength = USE_NORMAL ? normalStrength * pixelColor.a * fadeFactor : 0.0;
-			output.pbrStrength = pbrStrength * pixelColor.a * fadeFactor;
-			output.emissiveStrength = emissiveStrength * pixelColor.a * fadeFactor;
-		}
-
-
-		function fragment() {
 			{
 				var matrix = camera.inverseViewProj * global.modelViewInverse;
 				var screenPos = projectedPosition.xy / projectedPosition.w;
@@ -184,11 +173,18 @@ class DecalPBR extends BaseDecal {
 
 				calculatedUV = localPos.xy;
 				fadeFactor = 1 - clamp( pow( max( 0.0, abs(localPos.z * 2) - fadeStart) / (fadeEnd - fadeStart), fadePower), 0, 1);
+
+				if( CENTERED )
+					calculatedUV += 0.5;
 			}
+			output.albedoStrength = USE_ALBEDO ? albedoStrength * pixelColor.a * fadeFactor : 0.0;
+			output.normalStrength = USE_NORMAL ? normalStrength * pixelColor.a * fadeFactor : 0.0;
+			output.pbrStrength = pbrStrength * pixelColor.a * fadeFactor;
+			output.emissiveStrength = emissiveStrength * pixelColor.a * fadeFactor;
+		}
 
-			if( CENTERED )
-				calculatedUV += 0.5;
 
+		function fragment() {
 			if( USE_ALBEDO ) {
 				var albedo = albedoTexture.get(calculatedUV);
 				pixelColor *= albedo;