Skip to content

Commit 880e2eb

Browse files
fix(USDZExporter): alpha issues in diffuse map (#364)
1 parent 5bf7324 commit 880e2eb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/exporters/USDZExporter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ ${array.join('')}
323323
`${pad}color3f inputs:diffuseColor.connect = </Materials/Material_${material.id}/Texture_${material.map.id}_diffuse.outputs:rgb>`,
324324
)
325325

326+
// Include alpha input
327+
if (material.transparent || material.alphaTest > 0.0) {
328+
inputs.push(`${pad}float inputs:opacity.connect = </Materials/Material_${material.id}/Texture_${material.map.id}_diffuse.outputs:a>`);
329+
}
330+
331+
// Check if alpha test is bigger than minimum of 0.01, if not and it is transparent still apply a 0.01 alpha clip in order to remove white blur in transparent place.
332+
if (material.alphaTest > 0.01) {
333+
inputs.push(`${pad}float inputs:opacityThreshold = ${material.alphaTest}`);
334+
}
335+
else if(material.transparent || material.alphaTest > 0.0) {
336+
inputs.push(`${pad}float inputs:opacityThreshold = 0.01`);
337+
}
338+
326339
samplers.push(this.buildTexture(material, material.map, 'diffuse', material.color))
327340
} else {
328341
inputs.push(`${pad}color3f inputs:diffuseColor = ${this.buildColor(material.color)}`)
@@ -412,6 +425,7 @@ ${samplers.join('\n')}
412425

413426
this.textures[id] = texture
414427

428+
// Add the alpha output for when transparency is set or the alpha test is above 0
415429
return `
416430
def Shader "Transform2d_${mapType}" (
417431
sdrMetadata = {
@@ -436,6 +450,7 @@ ${samplers.join('\n')}
436450
float outputs:g
437451
float outputs:b
438452
float3 outputs:rgb
453+
${material.transparent || material.alphaTest > 0.0 ? 'float outputs:a' : ''}
439454
}`
440455
}
441456

0 commit comments

Comments
 (0)