Skip to content

Commit

Permalink
Merge branch 'main' into openupm
Browse files Browse the repository at this point in the history
  • Loading branch information
atteneder committed Aug 21, 2024
2 parents 9145e32 + be5c6f6 commit fbb84ea
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.7.1] - 2024-08-07

### Fixed
- (Export) Cases of corrupt glTFs when not all vertex attributes of a mesh were exported.
- Alpha blending via baseColorTexture's alpha value is now in correct color space, less opaque and as a result consistent with other glTF viewers (affected URP and built-in render pipeline projects in linear color space; fixes [#700](https://github.com/atteneder/glTFast/issues/700)).

## [6.7.0] - 2024-06-25

### Added
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Export/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GLTFast.Export
{
static class Constants
{
public const string version = "6.7.0";
public const string version = "6.7.1";

internal const string mimeTypePNG = "image/png";
internal const string mimeTypeJPG = "image/jpeg";
Expand Down
8 changes: 5 additions & 3 deletions Runtime/Scripts/Export/ExportSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ public enum FileConflictResolution
}

/// <summary>
/// Compression
/// glTF compression method.
/// </summary>
[Flags]
public enum Compression
{
/// <summary>No compression</summary>
Uncompressed = 1,
/// <summary>Replace existing files with newly created ones</summary>
/// <summary><a href="https://meshoptimizer.org/#vertexindex-buffer-compression">Meshopt compression</a>
/// via <see cref="Extension.MeshoptCompression"/></summary>
MeshOpt = 1 << 1,
/// <summary>Replace existing files with newly created ones</summary>
/// <summary><a href="https://google.github.io/draco/">Draco 3D Data compression</a>
/// via <see cref="Extension.DracoMeshCompression"/></summary>
Draco = 1 << 2,
}

Expand Down
31 changes: 15 additions & 16 deletions Runtime/Scripts/Export/GltfWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ enum State
struct AttributeData
{
public int stream;
public int offset;
public int inputOffset;
public int outputOffset;
public int accessorId;
public int size;
}
Expand Down Expand Up @@ -903,7 +904,8 @@ async Task BakeMesh(int meshId, UnityEngine.Mesh.MeshData meshData)

var attrData = new AttributeData
{
offset = inputStrides[attribute.stream],
inputOffset = inputStrides[attribute.stream],
outputOffset = outputStrides[attribute.stream],
stream = attribute.stream,
size = attribute.dimension * attributeSize
};
Expand All @@ -915,17 +917,14 @@ async Task BakeMesh(int meshId, UnityEngine.Mesh.MeshData meshData)
{
continue;
}
else
{
outputStrides[attribute.stream] += attrData.size;
}

outputStrides[attribute.stream] += attrData.size;
// Adhere data alignment rules
Assert.IsTrue(attrData.offset % 4 == 0);
Assert.IsTrue(attrData.outputOffset % 4 == 0);

var accessor = new Accessor
{
byteOffset = attrData.offset,
byteOffset = attrData.outputOffset,
componentType = Accessor.GetComponentType(attribute.format),
count = vertexCount,
};
Expand Down Expand Up @@ -1554,10 +1553,10 @@ NativeArray<byte> outputStream
{
var job = new ExportJobs.ConvertPositionFloatJob
{
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.offset,
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.inputOffset,
inputByteStride = inputByteStride,
outputByteStride = outputByteStride,
output = (byte*)outputStream.GetUnsafePtr() + attrData.offset
output = (byte*)outputStream.GetUnsafePtr() + attrData.outputOffset
}.Schedule(vertexCount, k_DefaultInnerLoopBatchCount);
return job;
}
Expand Down Expand Up @@ -1597,10 +1596,10 @@ NativeArray<byte> outputStream
{
var job = new ExportJobs.ConvertTangentFloatJob
{
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.offset,
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.inputOffset,
inputByteStride = inputByteStride,
outputByteStride = outputByteStride,
output = (byte*)outputStream.GetUnsafePtr() + attrData.offset
output = (byte*)outputStream.GetUnsafePtr() + attrData.outputOffset
}.Schedule(vertexCount, k_DefaultInnerLoopBatchCount);
return job;
}
Expand Down Expand Up @@ -1662,10 +1661,10 @@ NativeArray<byte> outputStream
{
var job = new ExportJobs.ConvertTexCoordFloatJob
{
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.offset,
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.inputOffset,
inputByteStride = inputByteStride,
outputByteStride = outputByteStride,
output = (byte*)outputStream.GetUnsafePtr() + attrData.offset
output = (byte*)outputStream.GetUnsafePtr() + attrData.outputOffset
}.Schedule(vertexCount, k_DefaultInnerLoopBatchCount);
return job;
}
Expand All @@ -1684,8 +1683,8 @@ NativeArray<byte> outputStream
inputByteStride = inputByteStride,
outputByteStride = outputByteStride,
byteLength = (uint)attrData.size,
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.offset,
output = (byte*)outputStream.GetUnsafePtr() + attrData.offset
input = (byte*)inputStream.GetUnsafeReadOnlyPtr() + attrData.inputOffset,
output = (byte*)outputStream.GetUnsafePtr() + attrData.outputOffset
}.Schedule(vertexCount, k_DefaultInnerLoopBatchCount);
return job;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ half Alpha(float2 uv)
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
return baseColorFactor.a;
#else
return tex2D(baseColorTexture, uv).a * baseColorFactor.a;
half alpha = tex2D(baseColorTexture, uv).a;
#ifndef UNITY_COLORSPACE_GAMMA
alpha = GammaToLinearSpace(alpha);
#endif
return alpha * baseColorFactor.a;
#endif
}

Expand Down
6 changes: 5 additions & 1 deletion Runtime/Shader/Built-In/glTFUnlit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ SubShader {

fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(baseColorTexture, i.texcoord) * baseColorFactor;
fixed4 col = tex2D(baseColorTexture, i.texcoord);
#ifndef UNITY_COLORSPACE_GAMMA
col.a = GammaToLinearSpace(col.a);
#endif
col *= baseColorFactor;
col *= i.color;
#ifdef _ALPHATEST_ON
clip(col.a - alphaCutoff);
Expand Down
Loading

0 comments on commit fbb84ea

Please sign in to comment.